The information is getting stored in the session and i am able to retrieve the same for single user. The trouble starts when 2 user logged in from different browser (for example chrome, IE) from the same machine. The 2nd logged in user, overwrite the session information of first user.
How to prevent this.
My environment: Windows 7 64 bit, IBM websphere server, Oracle 11g, JSP, Sevrlet.
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 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.