This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
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
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.
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.