• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hua Liang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Sargunam, Thanks a lot! Now I got it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic