I'm using Session objects in my JSP pages to keep track of which user's are administrators and which user's are not. I retrieve the user's Windows NT login, run a query against one of my database tables to see if the user is an admin, and if they are, then the appropriate admin buttons are provided.
If the user's login is in my table, the session object works fine and displays the appropriate name that I assign to it. However, if the user's login is not in my table, the Session object should display a default name that I've specified for it. But it doesn't do that. Instead, it shows the name of the person who accessed the site last whose login is in my table. Why is that? Below is the code I have so far:
The problem is that you have, if(rs == null), It is never going to be null if you get a record back or not. Then you go to the else side, and if there is no record it never enters the while statement. I would try somethin like..
Where are the Strings being declared? in something like <%! String firstName = null; %> ? I forget the actual syntax, but you probably see it in your code.
If so, then they are instance variables of the JSP/servlet. Every user will hit the same instance of the servlet. That's the way servlets/JSPs work; there is only one instance per JVM.
So, once someone logs in successfully, his or her name will be displayed until the next successful login (because your code is only updating the values upon successful login--due the null check that Jonathon pointed out).