Listener interface , Its Use and Events

1) javax.servlet.ServletContextAttributeListener

attributeAdded
attributeRemoved

attributeReplaced

Event
ServletContextAttributeEvent

Use
You want to know if an attribute in a
web app context has been added,

removed, or replaced.

2) javax.servlet.http.HttpSessionListener

sessionCreated

sessionDestroyed

Event
HttpSessionEvent

Use
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).

3) javax.servlet.ServletRequestListener
requestInitialized

requestDestroyed

Event
ServletRequestEvent

You want to know each time a
request comes in, so that you can

log it.

4)javax.servlet.ServletRequestAttributeListener

attributeAdded
attributeRemoved

attributeReplaced

Event
ServletRequestAttributeEvent

Use
You want to know when a
request attribute has been added,
removed, or replaced.

5)javax.servlet.http.HttpSessionBindingListener
valueBound

valueUnbound

Event
HttpSessionBindingEvent

Use
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.

6)javax.servlet.http.HttpSessionAttributeListener

attributeAdded
attributeRemoved
attributeReplaced

Event
HttpSessionBindingEvent

Use
You want to know when a session
attribute has been added, removed,

or replaced.

7)javax.servlet.ServletContextListener

contextInitialized

contextDestroyed

Event
ServletContextEvent

Use
You want to know if a context has

been created or destroyed.


8)javax.servlet.http.HttpSessionActivationListener
sessionDidActivate

sessionWillPassivate

Event
HttpSessionEvent

Use
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.