I am a little confused here, building a web application which has tab sheet. In in the tab sheet class I am using a data member – static String variable to store the tab selected by the user. I am doing this so that I can display the tab last selected by the user when ther user returns to the tab sheet. I am getting the desirable results. However, if I logout and login (after deleting the cache on browser), the tab sheet is still picking the tab which user had last selected and not picking the default tab. The tab sheet is being initialised by another component. What I dont understand is, does the class defination not garbage collected? why is it picking the old data? how to fix this?
Share
You seem to be assuming that making a variable static somehow corresponds to isolating it to a user session. It doesn’t.
If you want any sort of session handling, you’ll have to actually have a session. (You’ll need to consider what happens across server restarts, multiple servers etc.)
When you have a static variable, that’s one variable for that class in that classloader. It doesn’t have anything to do with the user. All users will see the same variable, if they hit the same server.
You haven’t told us anything about what technologies you’re using to build your web app, but basically you should look into what’s provided for you in terms of server-side user sessions – or propagate the information using hidden fields or something similar, so the server doesn’t need to keep track of it at all.