Servlet attributes for more than one JSP?

1

I have a Servlet that does the following:

L_sessao.setAttribute("Login", usuario);
response.sendRedirect("InicioCliente.jsp");

It sends the user name to the HomeClient.jsp page, on this page I can recover it without any problems. But I need it to send that same username to another page called Search.jsp.

Is this possible?

    
asked by anonymous 16.10.2018 / 20:33

2 answers

1

You can add the variable to an input of type hidden , Example: <input type="hidden" id="Login" name="Login" value="<%=usuario%>"> in ClientClient.jsp where the user variable is the one you want to pass to another screen. In the communication between .jsp and Servlet, you can also access the variables that are inside hidden inputs.

Within the Servlet method that will redirect to Search.jsp you will have access to the Login attribute using the HttpServletRequest method - getAttribute("Login") passing as parameter the input name.

    
17.10.2018 / 18:22
0

If you added the attribute in the session, you can retrieve it as follows.

Servlet

request.getSession(false).getAttribute("Login")

JSP

<%= session.getAttribute("Login") %>

Remembering that before retrieving the attribute, you need the object that represents your session.

    
16.10.2018 / 20:44