gpt4 book ai didi

java - 如何检查用户是否已协助并标记

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:18 25 4
gpt4 key购买 nike

我有以下代码,如果用户在一个事件中订阅,我希望 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);
}

ListaAcientes 拥有提供帮助的用户以及与之相关的事件 用户,代码:

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中添加一个 boolean 参数,您可以设置它(参数)
2/在 servlet 中,当用户单击“订阅”时,您将控制权传递给特定的 servlet,它将在其 session 中设置一个参数,您可以随时调用它

这是解决方案 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) { %>

<% } %>

关于java - 如何检查用户是否已协助并标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37830706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com