aspose file tools*
The moose likes Servlets and the fly likes How to deploy a ServletRequestListener to work only for specified Servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to deploy a ServletRequestListener to work only for specified Servlets?" Watch "How to deploy a ServletRequestListener to work only for specified Servlets?" New topic
Author

How to deploy a ServletRequestListener to work only for specified Servlets?

Nigel Chou
Ranch Hand

Joined: Oct 11, 2001
Posts: 47
It seems that DD only provides mechanism for Listeners to work for the whole application, instead of some specified Servlet. Am I right?
If it is true. I feel it is a flaw, since sometimes you may want you ServletRequestListener to work not on every request to all the Servlets in the application. It is inefficient.


SCJP for Java 2, SCWCD, SCMAD
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
I feel it is a flaw, since sometimes you may want you ServletRequestListener to work not on every request to all the Servlets in the application.

What about:

[ October 15, 2006: Message edited by: sven studde ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What are you trying to do with the listener?
Is is something that could be done with a filter?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Lijo Jacob
Greenhorn

Joined: Sep 02, 2004
Posts: 5
The ServletRequestListener is used to listen events on the request. There is no meaning in making it servlet specific. A request can be to any resource, need not be to a servlet.


Lijo Jacob<br />SCJP, SCWCD, SCBCD
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

People are always curious as to how to get the various listeners working in a web application. I hear that complaint so often, that I put together a flash, multimedia tutorial to demonstrate just that:

http://www.technicalfacilitation.com/examscam/tf/get.php?link=web

This deals with HttpSessionListeners an WebContextListeners, but coding and configuring all of the various Servlet and JSP API listeners is pretty much the same.

Do make sure there is an entry in your web.xml file:



As far as the class goes, it just has to implement the appropriate listener interfaces:



Here's the ear, which contains a functional war file. It was put together using IBM's Rational Application Developer (IRAD), but the war has been tested and runs fine on tomcat.

http://www.technicalfacilitation.com/examscam/tf/vangogh/09lifecyclelisteners.ear

Cheers!

-Cameron McKenzie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to deploy a ServletRequestListener to work only for specified Servlets?