Share on Google+Share on Google+


As we know that the Session is used to maintain the session between request.



As we know that the Session is used to maintain the session between request. Session object is responsible to hold the conversational state across  multiple requests.

The listener HttpSessionAttributeListener is an interface and extends the java.util.EventListener class. This listener will be called by the container whenever there there will be change to the attribute list on the servlet session of a web application. This listener is used when we want to know when a attribute has been added in a session, when a attribute has been removed and when it is replaced by another attribute. We can also say that this attribute is  used when the developer is interested to be notified when the session attribute changes. Now you may be wondering what is an attribute. An attribute is an object set or you can simply say that it is name/value pair where the name refers to a String and a value refers to the Object.

javax.servlet.http.HttpSessionAttributeListener interface has following methods:

  1. attributeAdded(HttpSessionBindingEvent event): It notifies whenever a new  attribute is added to the servlet session.
  2. attributeRemoved(HttpSessionBindingEvent event): It notifies whenever the attribute is removed from the servlet session.
  3. attributeReplaced(HttpSessionBindingEvent event): It notifies whenever the attribute gets replaced on the servlet session.

In the above methods you can see that we have used HttpSessionBindingEvent class as a parameter to the above methods. This class is a event class which is used for notifications when the changes are made to the attributes of  in a session.

The class HttpSessionBindingEvent has two methods:

  1. getName() : This method returns the name of the attribute that has been change in the session.
  2. getValue(): This method will return the value of the attribute that has been added, removed or replaced by other attribute.
  3. getSession(): This method will return the session that has been changed.


Posted on: May 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: HttpSessionAttributeListener  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Raja Mahesh
January 10, 2012
Require Information on Above Topic

You have mentioned above that HttpSessionBindingEvent class two methods... but u have mentioned 3 menthods like getName() , getValue() and getSession(), will the HttpSessionBindingEvent class will have 2 methods or 3 methods.. and if two methods what are that two methods.. ?? Thank you