This content has been marked as final. Show 4 replies
Presumably you're storing references to the same objects in both sessions. Your posted code doesn't provide any way to tell where you got those objects from.
Thanks for your reply.
I have a login page which takes user user input (login id & password) while submit it calls the servlet doPost method.
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
String loginId = request.getParameter(loginId );
String password = request.getParameters(pwd);
// Business logic: here i am checking if loginid and pwd is correct or not based on the value stored in the Database.
// Once the user is verified i am storing the information in the session. else i am displaying the error message to user.
session = request.getSession();
session.setAttribute("userName", userName );
session.setAttribute( "LoginId", loginId );
// user is now redirected to his home page.
// redirect to error page.
Every user will go through this cycle. The above works fine for single user. Once two user logon on different browser (Chrome and IE). The session information is overwritten.
I hope the problem is more clear now.
What is the scope of the userName variable? It needs to be method-local, not an instance or static member.
Excellent point re scope.
I was having the same issue (different environment).
My session & username variables were method local.
HttpSession httpSession = request.getSession(false) ; // get an existing session
String username = (String) httpSession.getAttribute("username") ;
But - the page I was serving with "welcome username" was static.
This looked like I was getting the wrong user session data.
The session data was fine, it was the static page I was serving that was the problem.
I had just missed "localizing" the page.
That solved the problem for me.