This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

HttpSessionBindingListener Interface

 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,
What is the practical use of implementatation of HttpSessionBindingListener interface?
Shriniwas
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Travis,Dilip & William
 
I didn't say it. I'm just telling you what this tiny ad said.
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic