Which of the events can be monitored by Java EE listeners?
[ Choose three ]
a.when a session is created
b.after a servlet is destroyed
c.when a session has timed out
d.when a cookie has been created
e.when a servlet has forwarded a request
f. when a session attribute value is changed
Choice A, Choice C and Choice F are correct
when a session is created - HttpSessionBindingListener
when a session has timed out - HttpSessionBindingListener
when a session attribute value is changed - HttpSessionAttributeListener
HttpSessionListener is used to receiving notification events about HttpSession lifecycle changes. It Receives notification that a session has been created. Receives notification that a session is about to be invalidated.
HttpSessionBindingListener - Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.
HttpSessionAttributeListener - This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application.
I think b is also an option. After a servlet is destroyed, the contextDestroyed method is called.
According to ServletContextListener API:
void contextDestroyed(ServletContextEvent sce)
Receives notification that the ServletContext is about to be shut down.
All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction.
sce - the ServletContextEvent containing the ServletContext that is being destroyed