About Question enthuware.jwpv6.2.1225 :

Moderator: admin

Post Reply
harsh.sahajwani
Posts: 13
Joined: Sun Jan 20, 2013 5:58 am
Contact:

Re: About Question enthuware.jwpv6.2.1225 :

Post 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 ?

admin
Site Admin
Posts: 10076
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.1225 :

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests