Events And Listener In Servlet


Events are primarily happening of Something. Switching the condition of an object is known as an Event.

We can perform certain important tasks at the occurrence of these Exceptions, for example counting total and current logged-in users, ,making tables of the database at the time of deploying the project, Creating database connection Objects etc.

javax.servlet and javax.servlet.http packages have many event classes and listener interfaces.

Event Classes

Event classes are as follows:

  1. ServletRequestEvent
  2. ServletContextEvent
  3. ServletRequestAttributeEvent
  4. ServletContextAttributeEvent
  5. HttpSessionEvent
  6. HttpSessionBindingEvent

Event Interfaces

The Event interfaces are as follows:

  1. ServletRequestListener
  2. ServletRequestAttributeListener
  3. ServletContextListener
  4. ServletContextAttributeListener
  5. HttpSessionListener
  6. HttpSessionAttributeListener
  7. HttpSessionBindingListener
  8. HttpSessionActivationListener

Forthcoming Topics in Servlet Events and Listeners:


Let’s Check the Simple example of ServletContextEvent and ServletContextListener.


Let’s Check The Simple Example of HttpSessionEvent and HttpSessionListener


Let’s check the simple Example of ServletRequestEvent and ServletRequestListener

4.#ServletContext AttributeEvent

Let’s check the simple examples of ServletContextAttributeEvent and ServletContextAttributeListener.


Let’s check the simple examples of HttpSessionBindingEvent and HttpSessionAttributeListener.


Let’s check the simple examples of ServletRequestAttributeEvent and ServletRequestAttributeEvent.