HFSJ said: ServletContextListener must be registered in DD, and HttpSessionBindingListener don't have to since it "happens automatically".
The API has this line "To receive notification events, the implementation class must be configured in the deployment descriptor for the web application." for all ctx and req listeners, as well as HttpSessionListener. For other 3 Session Listeners (HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionActivationListener), API doesn't mention this line.
Does it mean these 3 listeners don't need to register in DD? :roll: [ September 24, 2005: Message edited by: Will Lee ]
good question...help me to re-read the HFSJ, and remind of myself to that question.
according to HFSJ, page 254--HttpSessionListener, HttpSessionActivationListener, HttpSessionAttributeListener MUST be registered in DD.
and HttpSessionBindingListener, do not be configured in DD since the Container calls the event handling (valueBound() & valueUnbound()) when an intance of certain class is added to or removed from a session.
almost the same words from HFSJ.. well it is the SAME.
Diploma in Computer Studies
Formula 1 app by Maxis (Playbook)
I agree with you that HttpSessionBindingListener and HttpSessionActivationListener do not need to be declared in DD. However, my conclusion is based on my own logical guess. I just want to know which part of the spec does have a clear definition of this requirement?
Joined: Mar 16, 2005
check J2ee API (or servlet API, or maybe the spec.), There's description for HttpSessionListener: To be notified, the class of this type must be registered in DD.
and HFSJ only emphasized Binding and ActivationListener don't need to be, so I guess HttpSessionAttrListener may need this step.
Hi, according to HFSJ(Pg:254), HttpSessionActivationListener also need to be registered in DD. On what basis you guys are saying that it is not needed to register? But HFSJ book doesnt talk much on other types of listerners also. My question is request and context listeners need to be registerd in DD or not? I am guessing except HttpSessionBindingListner, all other listeners must be registered in DD.
SCJA, SCJP, SCWCD, SCBCD, SCDJWS.
Joined: Nov 16, 2003
according to HFSJ(Pg:254), HttpSessionActivationListener also need to be registered in DD. On what basis you guys are saying that it is not needed to register?
A trick to remember which event listeners to register in the DD :
The listeners can be classified in 2 categories:
1. Those that are interested in all events of one type(e.g. HttpSessionListener (interested in ALL Http session creation and destruction events), HttpSessionAttributeListener(interested in all session attribute events - any attribute added / removed / replaced), and all the listeners for ServletContext and ServletRequest.
The container creates one instance of each of these listeners.
2. Those that are interested only in specific events of one type. (there are 2 listeners of this type - HttpSessionBindingListener (interested in knowing when it is itself bound / unbound to a HttpSession) and HttpSessionActivationListener(interested in knowing when only the session it is bound to is activated or passivated, so that it can prepare itself for activation / passivation)
We create the instances of these listeners and set them as attributes in specific http sessions.
The first type of listeners are configured in the DD - as their methods are ALWAYS called when the event occurs.
The second type of listeners are not configured in the DD.
On page 262 in HFSJ, it is mentioned that HttpSessionActivationListener interface may usually be implemented by an attribute class or some other class. I think this is not correct - HttpSessionActivation should always be implemented by an attribute class. - Gouri [ September 27, 2005: Message edited by: Gouri Bargi ]
Joined: Mar 16, 2005
Yes, I agree. I think the HSActivationListener should not be implemented by "other" class.
Thanks for giving such detail explaination. I guess an easy way to remember is: All listener that are implemented by attribute obj. should NOT be registered in DD. They are HSBindingListener and HSActivationListener. For everything else (servlet context and request, other HttpSession listener), you must declare in DD. The order of them in DD matters.