It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes difference b/w HttpSessionBindingListner and HttpSessionAttributeListner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "difference b/w HttpSessionBindingListner and HttpSessionAttributeListner" Watch "difference b/w HttpSessionBindingListner and HttpSessionAttributeListner" New topic

difference b/w HttpSessionBindingListner and HttpSessionAttributeListner

ahmed, ishtiaq

Joined: Aug 02, 2001
Posts: 6
i wana know what is the difference b/w HttpSessionBindingListner and HttpSessionAttributeListner.
they i think have the same functionality (method)
attributeAdded() --- valueBound()
attributeRemoved() --- valueUnbound()

plz any one explain
syed ishtiaque ahmed
satish kolli

Joined: Sep 21, 2001
Posts: 24
They look the same as they generate the same event.
But the way they respond varies.
HttpSessionBindingListener - will notify the objects that
1. Implement this listener and
2. Are added to a session.
3. This will not notify the objects that implement this listener but are not added to the session.
4. Session Specific
HttpSessionAttributeListener - will notify the object that
1. implemetns this interface.
2. The object in question need not be a part [i.e added to the session] of the session to receive this notification.
3. Works accross sessions
4.notify the CONTAINER when you add/remove/replace an object from a session.
Good Tutorial on Listeners:
Satish Kolli
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
An object that implements HttpSessionAttributeListener (and is registered as a listener in web.xml) is notified anytime any object is added/removed/replaced in any session in the web application context. This is useful for an administrative console, for instance, that would allow an admin to view all session attributes across the application.
An object that implements HttpSessionBindingListener is notified anytime when that object itself is added to or removed from any session in the web application context. This is useful, for instance, if an object should log whenever it is bound to or unbound from a session.
Miftah Khan
- Sun Certified Programmer for the Java 2 Platform
- Sun Certified Web Component Developer for the J2EE Platform
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5382
May I say that
HttpSessionAttributeListener works at WebApplication level.(then object which implements it should exist through out the application i.e. should be in ServletContext)
HttpSessionBindingListener works at session level.
Plz correct me if I am wrong

"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
I agree. Here's the link:
subject: difference b/w HttpSessionBindingListner and HttpSessionAttributeListner
It's not a secret anymore!