Listeners

    `
  • In Servlet 2.3,It is part of the Java Servlet as defined but they have their own specific functionalities.

  • Listeners are defined as Java interfaces.

  • Listeners achieve some tasks during Life Cycle of Application for Developers.

  • Listener gives us a great control over application without disturbing architecture of the application.

Servlet Listener Interfaces
Package:-javax.Servlet
Interface Name:-ServletContextListener.
contextInitialized():- Creates Servlet Context.
contextDestroyed():- Destroy Servlet Context.
Package:-javax.Servlet
Interface Name:-ServletContextAttributeListener
attributeAdded:-Add the Attribute of Servlet Context Object.
attributeReplaced:-Replacement the Attribute of Servlet Context Object.
attributeRemoved:-Removal the Attribute of Servlet Context Object.
Package:-javax.Servlet.http
Interface Name:-HttpSessionListener
sessionCreated():-Create and invalidate the Session.
sessionDestroyed():-Timeout the session
Package: javax.Servlet.http
Interface:-HttpSessionAttributeListener.
attributeAdded():-Adds the Session Attribute.
attributeReplaced():-Replacement of Session Attribute.
attributeRemoved()Remove the Session Attribute.


Servlet Listener Event Classes
Class Methods
ServletContextListener getServletContext()
ServletContextAttributeEvent
extends ServletContextEvent
getName()
getValue()
HttpSessionEvent getSession()
HttpSessionBindingEvent
extends HttpSessionEvent
getName()
getValue()