File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session expiry

 
Amin Mohammed-Coleman
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am currently working on a JSP search component which uses sessions. The default session timeout is set at 30mins. In my JSP page I implement the following:

This exception is caught in an error page which states:
"Session has Expired. Please start again".

The problem is when i test this page after 30mins I get a NullPointerException. After debugging I've found out that certain objects that I have placed in the session have disappeared. So I modified my code to do the following:



However, this does not solve the problem in that after 30mins I still get NullPointerException and not displaying "Session has expired". In the error page I catch IllegalStateException and print out the session expiry statement.

Can anyone tell me what other criteria I should look for when the session has expired?

Thanks
[ June 07, 2005: Message edited by: amz ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just check to see if the object stored in session is null.
If so, either redirect or forward to the login page.
 
Amin Mohammed-Coleman
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Just check to see if the object stored in session is null.
If so, either redirect or forward to the login page.


I have been trying to implement this, but unfortunately I still get NullPointerException rather than session expiry page appearing.

Thanks
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"amz" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake and must constist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amz:


I have been trying to implement this, but unfortunately I still get NullPointerException rather than session expiry page appearing.

Thanks


A call to sendRedirect or forward doesn't stop the execution of a servlet or jsp on it's own.
Try adding a "return;" statement just after your redirect or forward.


 
Amin Mohammed-Coleman
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


The problem is that the my jsp page is a component inside another jsp page therefore i cannot use response.sendRedirect().

I have tried null == session.getAttribute("userBean")...but for some reason it still throws a NullPointerException.
 
Henrique Sousa
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amin Mohammed-Coleman:
I have tried null == session.getAttribute("userBean")...but for some reason it still throws a NullPointerException.


If your NullPointerException comes from that line, it probably means the session object is null, perhaps because you got it with getSession passing false[I] as argument.
One way out of it is to check if [I]session
is null.



Regards
 
Amin Mohammed-Coleman
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henrique Sousa:




Hi,
ok...I'm at the point of tearing my hair out! I've basically tried the following scenarios:

if session == null
if session.isRequestedSessionIdValid() !=true
if session.getAttribute("object") ==null

and i still get NullPointerException.

anymore advice will be much appreciated.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the line of code that is throwing the NullPointerException (NPE).
Also post the stack trace.
 
kirtikumar patel
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
had you been used isErrorpage=true flag in jsp page or not?if not,plz try it
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic