How to set the session correctly
Hi Friends,
I have a java based web app,and I set the session for the user like this after he logs in:
request.getSession().getServletContext().setAttribute("user",uname);
But the problem is,if I open a different browser,I can still see the user logged in from a different computer. So,is this happening becuase of the getServletContext() ?
Please suggest what's the right way to do it.
Thanks
[456 byte] By [
java80a] at [2007-11-27 2:14:27]

# 1
Indeed remove the getServletContext(). You should set attributes in the session, which is browser/user-specific and not in the servletContext, which is application-specific.
# 2
Hi,
Thanks for the help.
I have removed that getServletContext,and have it like this now:
request.getSession.setAttribute("user",uname);
But still,when I open a different browser the session gets carried over.
Is this application server specific thing, I am using Tomcat....i am totally confused
Thanks
# 3
In the first browser type the following line in the address bar.
javascript:document.cookie
Look for the cookie with the name JSESSIONID and note down the cookie value.
When you open a new browser and navigate to your web app do the same thing. If the two JSESSIONID values are the same then the browser's are sharing the session cookie and the session.
# 4
> when I open a different browserAre you talking about just a new instance of the same useragent (IE, FF, Opera, etc) or about a different useragent?
# 5
Hi,Thanks for the replies.I will try the JSessionId thing...BalusC,I am talking about a new instace of the same user-agent thing...didn't tried the other one.