[英]How to check if an user has asisted and mark it
我有以下代碼,我希望Asistir按鈕消失,如果用戶在一個事件中被捕,我應該在servlet和jsp中寫什么才能使它工作? 謝謝。
jsp按鈕
<a href="formularioAsiste.jsp?id=${ev.idEvento}" class="btn btn-default">
<span class="glyphicon glyphicon-check">Asistir</span>
</a>
顯示表的Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
GestionAsistentes gestionAsistentes = new GestionAsistentes();
GestionEventos gestionEventos = new GestionEventos();
Collection<Evento> listaEventos = gestionEventos.list();
Collection<Asiste> listaAsistentes = gestionAsistentes.list();
request.setAttribute("asistentes", listaAsistentes);
request.setAttribute("eventos", listaEventos);
request.getRequestDispatcher("tabla.jsp").forward(request, response);
// request.getRequestDispatcher("TablaEventosServlet").forward(request,
// response);
}
ListaAsistentes具有asist用戶和與該用戶相關的事件,代碼:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String strIdEvento = request.getParameter("evento");
Usuario asis = (Usuario) request.getSession().getAttribute("usuario");
GestionEventos gesEven = new GestionEventos();
Evento ev = gesEven.getEventoPorId(Integer.parseInt(strIdEvento));
String nombreEntidad = request.getParameter("nombreEntidad");
String nombreCuenta = request.getParameter("nombreCuenta");
String iban = request.getParameter("iban");
String numeroCuenta = request.getParameter("numeroCuenta");
Date fechaPago = new Date();
GestionAsistentes gestionAsistentes = new GestionAsistentes();
Asiste asistente = new Asiste(nombreEntidad, nombreCuenta, iban, numeroCuenta, fechaPago);
asistente.setPrimaryKey(new UsuarioEventoId(asis,ev));
gestionAsistentes.addAsistente(asistente);
request.setAttribute("asistentes", gestionAsistentes.list());
response.sendRedirect("TablaEventosServlet");
}
有兩種解決方案:
1 /當用戶訂閱你設置它時,在用戶的bean中添加一個布爾參數(參數)
2 /在servlet中,當用戶單擊subscibe時,您將控件傳遞給特定的servlet,它將在會話中設置一個參數,您可以隨時調用它
這是解決方案N°2的一個例子:
public class ExampleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//your code
request.getSession().setAttribute("subscribed", "isSubscribed");
RequestDispatcher view = request.getRequestDispatcher("My.jsp");
view.forward(request, response);
}}
然后在你的JSP中
<% String msg2=(String)request.getAttribute("subscribed");%>
<% if ( (msg2==null || msg2.isEmpty()) ) { %>
<a href="ExampleServlet?id=${ev.idEvento}" class="btn btn-default">
<span class="glyphicon glyphicon-check">Asistir</span>
</a>
<% } else if(msg2!=null) { %>
<% } %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.