Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

session expiry

 
Greenhorn
Posts: 15
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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 VI Editor Redhat
  • 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
  • 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.
 
Ranch Hand
Posts: 92
  • 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
  • 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 VI Editor Redhat
  • 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.
 
Greenhorn
Posts: 14
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic