• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Detecting expired sessions

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I can check in my servlet code whether a user currently
has a valid session. If there is not a valid session
is it possible to detect whether the user's session has been timed-out by WAS rather than the user never having had a session?
In some of my servlets I test for a valid seesion & forward
to the login page if necessary, I want to give a nice
message if the user has to login again if the session has timed out.
thanks
Steve McCain
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve McCain:
Hi,
I can check in my servlet code whether a user currently
has a valid session. If there is not a valid session
is it possible to detect whether the user's session has been timed-out by WAS rather than the user never having had a session?
In some of my servlets I test for a valid seesion & forward
to the login page if necessary, I want to give a nice
message if the user has to login again if the session has timed out.
thanks
Steve McCain


All you have to do to check for a valid session is use
HttpSession mySession = req.getSession(false);
if (mySession == null)
// redirect to login page
else
// do what you normally intended....
There is no way of finding out if a session timed out vs. the user never had one. However, you can be notified asynchronously when a session does time out by adding an object of type HttpSessionBindingListener to the HttpSession when it is created. See the spec for details.
Kyle


------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Steve McCain
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou Kyle, that confirms what I thought.
I'm not sure if I can do what I need to do by using a HttpSessionBindingListener because when the valueUnbound() is invoked, ie on session expiry, I won't have a servlet context & no request or response to forward to my login page. Am I missing something?
Steve
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic