This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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: 12682
    
    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


Java Resources at www.wbrogden.com
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
 
Similar Threads
Help abt session timeout ?
how to use session?
Session timeout not working
jboss session time out listener
session that never dies