File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes session time out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session time out" Watch "session time out" New topic
Author

session time out

gas das
Greenhorn

Joined: May 14, 2006
Posts: 5
Hi to all,
I have problems with session time out,
I'd like to know if there's a way to intercept session expire event.
In my web xml I have <session-timeout>20</session-timeout>
and it works, but I want to do call a function that use a session attribute before the session will be invalidated.
This function get userId from session and notify on database the user logout.
Do you know if I can map in my web-xml an handler,listener or something else?
Thanks a lot
Navert
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
If you keep reference to everything that needs to be cleaned up in an object that implements SessionBindingListener and is held in the session, then all of your cleanup can be done in the valueUnbound() method. This does not have to be declared in web.xml - in contrast to other types of listener.

When valueUnbound is called, you can NOT rely on any other part of the session being valid, thats why I say this object has to keep its own references to things that are used in cleanup.

Bill
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
Create a class which implements the HttpSessionLIstener interface and add it to the web.xml

Harpreet Hira
Ranch Hand

Joined: Sep 27, 2001
Posts: 72
Declare the listener in web.xml as described by Darren.
In the implementation class, put your cleanup-code in sessionDestroyed(HttpSessionEvent) method. This method is called by the container just before the session is invalidated.
gas das
Greenhorn

Joined: May 14, 2006
Posts: 5
ok great! I used HttpSessionListener and it works. thanks to all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session time out