File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session variable" Watch "Session variable" New topic

Session variable

ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76

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.

David O'Meara

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.

I agree. Here's the link:
subject: Session variable
It's not a secret anymore!