aspose file tools*
The moose likes Servlets and the fly likes HttpSessionBindingListener Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSessionBindingListener Interface" Watch "HttpSessionBindingListener Interface" New topic
Author

HttpSessionBindingListener Interface

Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Friends,
What is the practical use of implementatation of HttpSessionBindingListener interface?
Shriniwas
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
For one thing, the HttpSessionBindingListener interface solves a problem related to the handling of user session invalidation. A session can become invalidated by:
1. The action of your servlet - when a user logs out
2. The action of the servlet container - at expiration of the timeout
If you have an object that has to do some "cleanup" before it is discarded, have it implement HttpSessionBindingListener.
Bill
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Originally posted by William Brogden:
For one thing, the HttpSessionBindingListener interface solves a problem related to the handling of user session invalidation. A session can become invalidated by:
1. The action of your servlet - when a user logs out
2. The action of the servlet container - at expiration of the timeout
If you have an object that has to do some "cleanup" before it is discarded, have it implement HttpSessionBindingListener.
Bill


William,

I think HttpSessionListener for what you meant.

HttpSessionBindingListener is typically used to get notified when a object is set in or removed from session scope using setAttribute or removeAttribute method of HttpSession.

is it not always called back whenver we manipulate the session object?

Did I misunderstand that?
[ June 13, 2006: Message edited by: Dilip Kumar Jain ]

Manesh
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
The HttpSessionBindingListener can be used for objects that you plan to store into your session attributes, so they know when they are attached as a session attribute (with session.setAttribute).

In general anything that you would need to do when something when it is placed onto, or removed from a session attribute could do its own handling when it implements this interface.

One example might be a component that would be set into the session when the session is created or a user logs on, and would stay there the entire time the user is logged in, or the lifetime of the session. This component could log a message to a user activity log when in the valueBound() method, when it was placed onto the session attribute, and log another user logged out message in the valueUnbound, when the component got removed from the session attributes, such as on log out or when the session was destroyed.

Another example might be if you were storing a connection handle to an external resource for the session, such as database connection per session, the connector component could implement HttpSessionBindingListener to clean up its resources when it is removed from the session (and would not be needed by application anymore)

Objects that implement this interface do not have a listener deployment entry in the web.xml.

This is similar to HttpSessionActivationListener, where implementations get notified when servlet container activates or deactivates the session, which happens when a web application is reloaded, or in a cluster environment when the session is being transferred to other nodes in the cluster.


Error: Keyboard not attached. Press F1 to continue.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Thanks Travis,Dilip & William
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionBindingListener Interface