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

how to return a page to infor client when the session time out ?

 
luxica peng
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,everyone:
I have seen on some web a page may return to browser when the session time out.I only know the HttpSessionListner has this function.but we often use a response to return page,from the listner we can get the session by the HttpSessionEvent,but how can I get the response?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a listener for this.

When the user logs in, bind an object to session (let's call it 'userBean').
With every subsequent request, check for the existence of this object.
If request.getSession().getAttribute("userBean") is null then the user has either not logged in or has let their session time out.
In that case forward or redirect to the login page.

A filter makes it easy to put this checking fuctionality in front of every request without having to update all of your servlets.

I have an example app that does this on:
http://simple.souther.us/not-so-simple.html
Look for SessionMonitor
 
luxica peng
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is valuably.thanks,Ben.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic