Sending Servlet attributes to more than one JSP?

Asked

Viewed 104 times

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 problems. However, I need her to send that same user name to another page called Search.jsp.

That is possible?

  • But which page will the user see? Startclient.jsp or Search.jsp? But, as @renanzin explained, if you added the attribute in the session, any page can access it.

2 answers

1

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

Servlet

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

JSP

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

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

0

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

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.