Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionBindingListener Interface

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
What is the practical use of implementatation of HttpSessionBindingListener interface?
Shriniwas
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Travis,Dilip & William
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic