This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What's the difference between HttpSessionAttributeListener and HttpSessionBinding... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What Watch "What New topic
Author

What's the difference between HttpSessionAttributeListener and HttpSessionBinding...

Hua Liang
Greenhorn

Joined: Dec 24, 2003
Posts: 4
When the following is executed:

session.setAttribute("newAttribute", "value"); //newAttribute is a totally new Attribute

What happen?
I've been told that the HttpSessionBindingListener can be notified. How about the "HttpSessionAttributeListener" which has the "attributeAdded" method? Will it be notified?
Thanks for reply!
Vijay Sargunam
Greenhorn

Joined: Jan 14, 2004
Posts: 11
Hello,
SessionAttributeListeners are used when any attribute is bound, removed or replaced in session. But sessionBinderListener is used when only particular att
If you want to track any attribute added, removed or replaced in session you need to implement SessionAttributeListener. Any attribute in this scenario means, of any datatype viz, String, Integer, Products(Custom).
To do this, we need to create a class which implements the SessionAttributeListener and implement the 3 methods. Anytime, any attribute is added, remove, replaced, the corresponding events will be fired by the container.
However, if you have a class say Product, and you want to track any instance of Product added to session, then you have implement SessionBinderListener on Product class. ie.
public class Product implements SessionBinderListener
and you need to implement the corresponding methods.
So anytime, a instance of product is added to session, then the corresponding methods viz sessionBound() etc will be called by the container.
I guess it helps.
Regards,
Vijay
Hua Liang
Greenhorn

Joined: Dec 24, 2003
Posts: 4
Vijay Sargunam, Thanks a lot! Now I got it!
 
jQuery in Action, 2nd edition
 
subject: What's the difference between HttpSessionAttributeListener and HttpSessionBinding...