aspose file tools*
The moose likes JSP and the fly likes session expiry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session expiry" Watch "session expiry" New topic
Author

session expiry

Amin Mohammed-Coleman
Greenhorn

Joined: Oct 18, 2004
Posts: 15
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

Joined: Dec 11, 2004
Posts: 13410

Just check to see if the object stored in session is null.
If so, either redirect or forward to the login page.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Amin Mohammed-Coleman
Greenhorn

Joined: Oct 18, 2004
Posts: 15
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

Joined: Oct 18, 2000
Posts: 4121

"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!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Oct 18, 2004
Posts: 15
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

Joined: Apr 29, 2004
Posts: 92
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


Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Amin Mohammed-Coleman
Greenhorn

Joined: Oct 18, 2004
Posts: 15
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

Joined: Dec 11, 2004
Posts: 13410

Post the line of code that is throwing the NullPointerException (NPE).
Also post the stack trace.
kirtikumar patel
Greenhorn

Joined: Jun 29, 2005
Posts: 14
hi!
had you been used isErrorpage=true flag in jsp page or not?if not,plz try it


kirti patel<br />software engiener<br />pune
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session expiry