• 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

Servlet 2.3 question: Is there a way to determine session expiration?

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have discussed this issue before, and after looking through the new Servlet 2.3 API, I still dont see any changes with regards to checking the time stamp of a session to determine if the session has expired. The method getLastAccessedTime() returns the last time in which the client sent a request associated with the session. This number is always equal to the current time, which, for the most part, is useless. But if you think about it, you actually want the *second* to last time the client sent a request with the session because knowing this information allows you to quickly calculate the difference in time between the current time and the second to last time the client accessed the session.
Is there an easy way to do this? I was thinking about storing a value in the session called "lastAccessedTime" and assigning it a value equal to the second to last time the client accessed the session. Then, upon getting the session from the request, I can subtract this value from the current time and compare it to a predetermined number that represents the maximum number of millisseconds a session is allowed to exist before it is marked as "expired."
I'm using Weblogic 6.1, and I'm new to it, but I'm willing to bet that Weblogic makes this problem much easier.
Any help would be appreciated, thanks,
SAF
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Safrole,
Not sure if this is what you're trying to get at, but couldn't you define and register an HttpSessionListener, which will be notified when an HttpSession is created or invalidated. Once notified, this Listener could retrieve the session that changed and look at the getCreationTime() value to see if it is "old" enough to have timed out.
Hope this helps. It may be something you've already tried.
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I've looked into that, but had some problems with it. I think storing a value named "lastAccessedTime" in the session and manually updating this value each time the client sends a request within the context of the session is probably the easiest way to determine session expiration.
I think I'm getting too complicated for a simple problem. I have a tendency of doing that because I want to look cool as I develop my code ;D hehehe, ok, that was a joke
Thanks for the advice.
SAF
 
reply
    Bookmark Topic Watch Topic
  • New Topic