Click here to Skip to main content
15,887,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create session on JSP and set attribute "userName", but I can get this attribute only on first page. When I go to the next page, attribute "userName" is lost. How can I solve this problem ?

HttpSession session = request.getSession(true);
LoginManager loginManager = new LoginManager();
String name = loginManager.getUserName(request.getParameter("login"),
                request.getParameter("pass"));
view = request.getRequestDispatcher("index.jsp");
session.setAttribute("userName", name);
view.forward(request, response);


I try session.setMaxInactiveInterval(600), but it did not help me.

thanks!
Posted

1 solution

You forgot to include the next page code.

Anyway here a simple tutorial. JSP Sessions[^]
setAttribute/getAttribute properties used save/access session values.
 
Share this answer
 
Comments
alybin 23-Aug-13 8:18am    
My next page code
<%
String name = (String) session.getAttribute("userName");
if (name == null) {
response.sendRedirect("view/jsp/login.jsp");
} else {...
%>
alybin 23-Aug-13 8:25am    
I want to save the attribute "userName" before calling 'invalidate' or 'removeAttribute', but it lost after redirect to next page or reload.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900