permaculture playing cards*
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
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
 
Similar Threads
getting null pointer exeception
Question on Boxing
ByteArrayOutputStream size returns null.
Implicit session object becomes null in JSP
null pointer exception using session factory