wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Registration of Session Listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Registration of Session Listeners" Watch "Registration of Session Listeners" New topic
Author

Registration of Session Listeners

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

As far as Session Listeners are concerned, I'm a little confused about whether or not it is mandatory for the HttpSessionAttributeListener to be registered in the DD. This is my understanding:-

Following listener does not have to be registered, but can be:
HttpSessionBindingListener

Following listeners do have to be registered:
HttpSessionListener
HttpSessionActivationListener
HttpSessionAttributeListener

Could someone please confirm if this is correct?


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Icaro Dourado
Greenhorn

Joined: Dec 30, 2007
Posts: 9
I suppose every listener should be declared in your DD, otherwise how could they be found?


SCJP 5, SCWCD 5
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Take a look at this: http://www.coderanch.com/how-to/java/DeclaringListeners

Those who are interested in specific types of events (like the two from the group number 2 in the link above) doesn't have to be declared.
The point is that listeners from group 1 has to be called by the container every time something changes. You don't know what particular object can change - you are listening on all events.

The second group is quite different. The container will try to execute particular method on the object and it will execute (if it's provided) or not (if it's not provided). Container doesn't need any extra information about these kind of listeners - it just tries to execute this method.

Talking about HttpSessionBindingListener - the container just executes valueBound(-) on object after you add it to the session.

HTH!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Thanks for the answer Pedro. I'm glad I asked the question here, because I was mistakenly going with what was in the HFSJ book.

So then I should amend what I wrote before to this:

Following listeners do not have to be registered, but can be:
HttpSessionBindingListener
HttpSessionActivationListener

Following listeners do have to be registered:
HttpSessionListener
HttpSessionAttributeListener
All ServletContext & ServletRequest event Listeners
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

That's correct Nidhi :-)

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Registration of Session Listeners
 
Similar Threads
HttpSessionActionListener and DD
HttpSessionAttributeListener and HttpSessionBindingListener???
Doubt in Enthuware Questions
listener notification order / HFSJ CH5#11 doubt
what listeners don't need to register in DD