Page 1 of 1

Re: About Question enthuware.jwpv6.2.1225 :

Posted: Tue Jan 22, 2013 12:43 pm
by harsh.sahajwani
The explanation of this question states that classes implementing HttpSessionActivationListener and HttpSessionBindingListener, are NOT registered as listeners in web.xml

Page 256 of Head First Servlets and JSP 2nd Edition states that only HttpSessionBindingListener is NOT registered in web.xml, and HttpSessionListener and HttpSessionActivationListener are configured in web.xml.

This is confusing.

Can you please, confirm which all listeners need to be configured in web.xml and if possible, why?

1. ServletContextListener - Yes / No ?
2. ServletContextAttributeListener - Yes / No ?
3. ServletRequestListener - Yes / No ?
4. ServletRequestAttributeListener - Yes / No ?
5. HttpSessionListener - Yes / No ?
6. HttpSessionAttributeListener - Yes / No ?
7. HttpSessionBindingListener - Yes / No ?
8. HttpSessionActivationListener - Yes / No ?

Re: About Question enthuware.jwpv6.2.1225 :

Posted: Tue Jan 22, 2013 1:00 pm
by admin
If you look at the JavaDoc API description, for example, http://docs.oracle.com/javaee/6/api/jav ... tener.html, it clearly mentions:
In order to receive these notification events, the implementation class must be either declared in the deployment descriptor of the web application, annotated with WebListener, or registered via one of the addListener methods defined on ServletContext.
But for HttpSessionActivationListener and HttpSessionBindingListener, it doesn't say that.

You can confirm about the others from the JavaDoc.

Also, take a look at Section 4.4.3 of Servlet 3.0 specification. The ones that can be added to a ServletContext programmatically are the ones that need to be configured in web.xml or through annotations.

Further, take a look at section 8.1.4, it lists the interfaces that can be annotated with @WebListener. HttpSessionActivationListener is not listed.

HTH,
Paul.