Session mix-up

Hi..

im having problem with session in servlets.. my application uses jsp, servlets and ejbs..

when i login and go thru modules of applications, sometimes session mixes-up with other users. and im getting other users information instead of mine.

pls do suggest me in this...

thnx in advance...

[325 byte] By [jannuwinoda] at [2007-10-2 13:00:34]
# 1

Hi,

U get session-id and compare it with the previous page's session.

HttpSession session = request.getSession(true);

ses_id = session.getId() -->this will return session-id associated with this session.

Before going to next page, set the session attribute like,

session.setAttribute("ses_id" , ses_id);

and in the next page retrieve it as,

session.getAttribute("ses_id"); and compare with the current session.

Hope this would help u.

Java_novicea at 2007-7-13 10:20:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Are you sure it is the session that is getting mixed up and not something else? Make sure that none of your servlets are using instance variables to hold information specific to a request. Multiple threads of your servlet could be running simultaneously and the inappropriate use of instance variables could result in the "mix-up" of data between multiple sessions.

Gita_Weinera at 2007-7-13 10:20:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> Are you sure it is the session that is getting mixed

> up and not something else? Make sure that none of

> your servlets are using instance variables to hold

> information specific to a request. Multiple threads

> of your servlet could be running simultaneously and

> the inappropriate use of instance variables could

> result in the "mix-up" of data between multiple

> sessions.

Yes indeed, a lack of thread safety will cause this.

%

duffymoa at 2007-7-13 10:20:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Make sure that you are not using and setting values to static and instance members of a class. These will get shared between multiple threads handling simultaneous request to servlets.
garudaa at 2007-7-13 10:20:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...