Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session variable

 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic