It's not a secret anymore!*
The moose likes Tomcat and the fly likes Weird session behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Weird session behavior" Watch "Weird session behavior" New topic
Author

Weird session behavior

Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
Hi !

I have web application that uses session and store objects in those sessions and it looks like some of those objects are shared from one session to another ... I'm just saving the objects with session.setAttribute and getting the objects with session.getAttribute. The objects are not static at all... And in another environment, it works just nice so maybe it's a tomcat configuration problem ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Are you talking about the session data being shared between windows on the same system, or on completely separate systems?

If the latter, that's usually a red flag that you've create thread-safety issues in your code.

Do you have any instance variables in your servlets? JSP declaration blocks in your JSPs?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
On the same tomcat server, the data saved into the sessions are being shared for all the sessions (or a session.setAttribute just orverride everything).
I'm logging on 2 different computers going to the same tomcat server and the sessions are just returning the same objects, but the sessions have different session ids... And I don't think that it's a thread issue. Nothing is declared as static in the objects that I save in the sesion (except constants of course...)
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
I'm using tomcat in debug mode, maybe it has something to do with it...
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
nope, the problem doesn't seems to be the debug mode
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
The object that I save have instance variables that are objects themselves... And I'm saving the "master" object in the session.. I don't know why but could that be a problem ?
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
I'm using struts and I save the object in the ActionClass as an instance variable... I think this is the problem...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

It's been years since I've been burdened by Struts, but if I recall correctly Actions must be written in a thread-safe manner. That means no instance variables.
Marc Larochelle
Greenhorn

Joined: Sep 16, 2005
Posts: 14
Yea... That looks like it was the problem. normally, as I just learned, struts gives you a unique object but it could be used after that. So if I set up the property each time I get into the Action, it should be ok (before I looked if the property was null so I was not resetting it).

Thanks for your help !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird session behavior