File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Listener configure in DD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Listener configure in DD" Watch "Listener configure in DD" New topic
Author

Listener configure in DD

gunjan deogam
Greenhorn

Joined: Aug 02, 2009
Posts: 11

Please can any one clear me which listener are configure in DD and which are not?


Gunjan Deogam SCJP6, SCWCD5
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1715
    
  25

Hi Gunjan,

In the web.xml:
ServletRequestListener
ServletRequestAttributeListener
HttpSessionListener
HttpSessionAttributeListener
ServletContextListener
ServletContextAttributeListener

and not in the web.xml
HttpSessionBindingListener
HttpSessionActivationListener

Regards,
Frits
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

HttpSessionActivationListener is also configurable in the DD. You can configure it in the DD if you want to listen for when a session migrates to another VM. It can also be implemented by a session attribute class to prepare the attribute for the migration.


SCJP 6 || SCWCD 5
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1715
    
  25

Hi Michael,

I don't think that is correct. According to the book of Sun Certified Web Component Developer Study Guide (by David Bridgewater) it is not like that:
Chapter 4:
Now we move on to two other session-related listeners which are different in character
to the listeners we have previously encountered, whether on session, request, or
context. These listeners are:
HttpSessionBindingListener
HttpSessionActivationListener
Classes implementing these listener interfaces are not declared in the deployment
descriptor. They become known to the web container through a different mechanism
entirely.

I checked the servlet 2.4 specs and it also confirms this

SRV.15.1.8 HttpSessionActivationListener
Objects that are bound to a session may listen to container events notifying them
that sessions will be passivated and that session will be activated. A container that
migrates session between VMs or persists sessions is required to notify all
attributes bound to sessions implementing HttpSessionActivationListener.

because they don't mention the phrase:
To receive notification events, the implementation
class must be configured in the deployment descriptor for the web application

or did I miss something?
Regards,
Frits
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

Hi Frits,

I'm reading the Head First Servlets and JSP book and it says that it can go both ways. It says that it's used when

You want to know when a session attribute has been added, removed, or replaced (p.182).


and also when

You want to know when a session moves from one VM to another (p.264).


In an exercise (p.264), it asks the reader to mark whether the listener is used on an attribute class or defined in the DD and HttpSessionActivationListener has checkmarks next to both. But I've never written a distributed Java web app, so I don't know for sure.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Check this FAQ.


[My Blog]
All roads lead to JavaRanch
gunjan deogam
Greenhorn

Joined: Aug 02, 2009
Posts: 11

Thanks all of you. But I read that HttpSessionActivationListener configure in DD.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

gunjan deogam wrote:Thanks all of you. But I read that HttpSessionActivationListener configure in DD.

Where ?
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

The FAQ that Christophe referred to says that the Head First Servlets and JSP book has an error concerning this, so this is probably what I saw.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listener configure in DD