• 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

Alternate method to HttpSession's getLastAccessedTime()

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
Is there any alternative for this method
HttpSession's getLastAccessedTime();
Thank you in advance.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why you need an alternative? and what are you trying to achieve?
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ansari
Thanks for reply..
Iam assigning HttpSessionBindingEvent.getSession() to HttpSession variable in a Listener class..
what I need is getLastAccessedTime();and getMaxInactiveInterval()...iam able extract maxInactive interval time...but when I invoke getLastAccessedTime()..it is throwing IllegalStateException....
I thought if there is any alternate way...
Thank you
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, we encounter IllegalStateException upon invoking getLastAccessedTime() on an invalidated session. Whereas the other method will give you the result anyway.

Can you show the code snippet?
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ansari,
I knew that it is being invalidated session..
it goes like this.....
HttpSession session = bindingEvent.getSession();
long l_access = session.getLastAccessedTime();
......
Thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats what the API says - binding listener gets called when the container is invalidating the session.
So why not make your session variable hold its own copy of the access time, updated every time the session is accessed.
Bill
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats what the API says - binding listener gets called when the container is invalidating the session.

Thank you William,
Please can you elaborate the above.
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thats what the API says - binding listener gets called when the container is invalidating the session.
So why not make your session variable hold its own copy of the access time, updated every time the session is accessed.



Thank you william,
Please can you elaborate the above.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set the last accessed time as your session attribute upon each request.

Something like below



I hope you get the point.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Iam assigning HttpSessionBindingEvent.getSession() to HttpSession variable in a Listener class..



As I understand it, you have created a class implementing HttpSessionBindingListener and attach an instance of this class to each new session. In the valueUnbound method you are trying to get at the session with the Event getSession() method so you can use the session method getLastAccessedTime() - this fails because at this point the session is invalid.

What I am saying is to add a timestamp variable to this custom class - update it everytime you process a request. When the valueUnbound method is called you will have the last access time in the object and wont have to call a session method.

Bill
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friendss,
my problem solved using HttpSessionListener.
Thank you very much for your inputs.
 
reply
    Bookmark Topic Watch Topic
  • New Topic