开发者

can valueUnbound() method of HttpSessionBindingListener be used to get informed whenever a session is about to be destroyed?

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 destroy开发者_运维技巧ed, along with HttpSessionListener.sessionDestroyed. How is that possible ?


You can add a dummy object that implements HttpSessionBindingListener to the session and never remove it. Then invocation of its valueUnbound() 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 HttpSessionListener manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜