I thought from my earlier post I had the scope of the session attribute understood.
I have a web app located on the web server. When a user logs on several session attributes are set and on a main menu page a message displays their name.
Today I found out that if one user has logged in everything appears to be ok. But when a second user logs on the fisrt users main menu message will display the second users name and it appears that all the session attibutes for the first user is changed to the second users log on criteria.
Please help I thought that each user logging on instanciated totally different and separate session.
No laughter, everyone was a n00b at this at one point.
Even though each user has their own session, there is only one instance of the servlet. You are using class and instance variables in the servlet. Bad bad news! Remove all class and instance variables and store temporary information in variables within the methods, and permanent info in the session.
Since there is only one instance of this servlet, all requests share, update, and read from the same variables.
Joined: Nov 16, 2004
Originally posted by Bear Bibeault: No laughter, everyone was a n00b at this at one point.
You are using class and instance variables in the servlet. Bad bad news! Remove all class and instance variables and store temporary information in variables within the methods, and permanent info in the session.
From my code posted can you give me some specifics. I am thinking the MiscObjects might be one problem. Here I think each session would need to instanciate a new MiscObjects. Is this the sort of thing you are talking about?
Disregarding the servlet-ness for a moment, you also have a bigger problem with general Java concepts. Many of your variables are declared public. Generally variables should be private. And what's with the static variables?
In a non-servlet class this is going to cause you no end of issues.
In short, yes, moving your variable declarations inside your doPost/doGet methods will take care of the problem you originally reported.
A good rule of thumb is to not never use instance variables (or static class level variables) in servlets unless you A) really know what you're doing and B) have a very good reason to do so
If the compiler is warning you that a variable might not have been initialized it's because it's possible for the part of the code that uses that variable to be reached without going through the code that initializes it.
On any day but Wednesday, the code on line 4 will never be executed so the name variable will be undeclared by the time line 7 is reached.
Look for a similar situation in your servlet code. [ January 25, 2008: Message edited by: Ben Souther ]
Joined: Nov 16, 2004
Ok I think I have the variable problem solved. But now my JSP is giving an error:
It would be better to start it in a new thread. This one is already long and many people will get annoyed to find out that, after reading 8 or 9 posts with lots of code, that the topic changed and that all their time reading the beginning was a waste.