This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Session variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session variable" Watch "Session variable" New topic
Author

Session variable

ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi,

I am creating a logout application using servlets. I am using session variables for logging off. But, I am getting a null pointer exception while using sessions.
The code is:
HttpSession session = request.getSession(false);
if(session != null) {
session.invalidate(); // null pointer exception here
}
Do I also need to create any session variables in login page also ?

Please let me know, where I am going wrong.

Thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Depending on the container, the user credentials may or may not be contained on the session, and there may not even be a session. It is possible that this is what you are seeing.

You should check the documentation for your particular server, for example WebSphere uses a separate cookie to maintain authentication, and this cookie is not related to the session. Assume that one implies the other creates application errors. You also need to use the SSOAuthenticator.logout() to logout.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session variable