Servlet’s Life moment Listeners

Scenario  Listener interface  Event type
 You want to know if an attribute in a web app context has been added, removed, or replaced. javax.servlet.ServletContextAttributeListener
attributeAdded
attributeRemoved
attributeReplaced
ServletContextAttributeEvent
 You want to know how many concurrent users there are. In other words, you want to track the active sessions. (We cover sessions in detail in the next chapter).  javax.servlet.http.HttpSessionListener
sessionCreated
sessionDestroyed
 HttpSessionEvent
 You want to know each time a request comes in, so that you can log it.  javax.servlet.ServletRequestListener
requestInitialized
requestDestroyed
 ServletRequestEvent
 You want to know when a request attribute has been added, removed, or replaced. javax.servlet.ServletRequestAttributeListener
attributeAdded
attributeRemoved
attributeReplaced
ServletRequestAttributeEvent
 You have an attribute class (a class for an object that will be stored as an attribute) and you want objects of this type to be notified when they are bound to or removed from a session. javax.servlet.http.HttpSessionBindingListener
valueBound
valueUnbound
 HttpSessionBindingEvent
 You want to know when a session attribute has been added, removed, or replaced. javax.servlet.http.HttpSessionAttributeListener
attributeAdded
attributeRemoved
attributeReplaced
 HttpSessionBindingEvent
 You want to know if a context has been created or destroyed.  javax.servlet.ServletContextListener
contextInitialized
contextDestroyed
 ServletContextEvent
 You have an attribute class, and you want objects of this type to be notified when the session to which they’re bound is migrating to and from another JVM. javax.servlet.http.HttpSessionActivationListener
sessionDidActivate
sessionWillPassivate
 HttpSessionEvent
Rate this post

Leave a Reply