ServletContextAttributeListener

ServletContextAttributeListener


Posted in : Java Posted on : June 23, 2011 at 8:01 PM Comments : [ 0 ]

In this section we will discuss about ServletContextAttributeListener.

ServletContextAttributeListener

In this section we will discuss about ServletContextAttributeListener.

ServletContextAttributeListener is an interface and extends the java.util.EventListener. Cause to existence of this listener is that it receives notifies about the changing into ServletContext attributes events. We should have to assure, for the configuration of the implemented class in the deployment descriptor file for the web application, before the notification gotted by the container. This interface is implemented when there is a requirement of adding, removing and replacing of attributes or in other word we can say this interface is implemented by a developer when they required any changing in the context attributes.

Methods of ServletContextAttributeListener :

This interface has three methods :

attributeAdded() : This method is notified when the attributes has been added to the ServletContext.

              syntax : void attributeAdded(ServletContextAttributeEvent e); 

attributeRemoved() : This method is notified when the attributes has been removed from the ServletContext.

              syntax : void attributeRemoved(ServletContextAttributeEvent e);

attributeReplaced() : This method is notified when the attributes has been replaced with the another attribute.

              syntax : void attributeAdded(ServletContextAttributeEvent e);

In the above methods a class ServletContextAttributeEvent is introduced. Lets see some explanation of this class :

This class is construct under the javax.Servlet interface and it extends the ServletContextEvent event class. This is an event class which is notified for the changing into the attributes of the ServletContext of a web application.

This method has the following methods :

getName() :

           syntax : public java.lang.String getName();

getValue() :

           syntax : public java.lang.Object getValue();

Listener in web.xml

<web-app>
<listener>
<listener-class>NameOfClassRespondsToWebApplicationEvent</listener-class>
</listener>
</web-app>

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics