Forums Register Login

Alternate method to HttpSession's getLastAccessedTime()

+Pie Number of slices to send: Send
Hi friends,
Is there any alternative for this method
HttpSession's getLastAccessedTime();
Thank you in advance.
+Pie Number of slices to send: Send
Why you need an alternative? and what are you trying to achieve?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
hi Ansari,
I knew that it is being invalidated session..
it goes like this.....
HttpSession session = bindingEvent.getSession();
long l_access = session.getLastAccessedTime();
......
Thanks
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
You can set the last accessed time as your session attribute upon each request.

Something like below



I hope you get the point.
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
Hi friendss,
my problem solved using HttpSessionListener.
Thank you very much for your inputs.
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4099 times.
Similar Threads
URLConnection and Java HttpSession's
URLConnection and Java HttpSession's
usable link to jdiscuss
getVariableResolver() & resolveVariable()
Alternatives to GWT for use with Liferay
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:52:35.