The valueUnbound() method of HttpSessionBindingListener is used to inform the attribute’s object which was added as an attribute in an Http session, that it has been removed from the session. In “HeadFirst JSP and Servlets“, they say that it can also be indirectly used to notify the application whenever a session is about to be destroyed, along with HttpSessionListener.sessionDestroyed. How is that possible ?
The valueUnbound() method of HttpSessionBindingListener is used to inform the attribute’s object which was
Share
You can add a dummy object that implements
HttpSessionBindingListenerto the session and never remove it. Then invocation of itsvalueUnbound()would indicate that session is about to be destroyed, and you can do some actions there.The advantage of this approach is that you can add multiple such objects with different callbacks instead of keeping track of different callbacks in
HttpSessionListenermanually.