File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Listeners Vs Filters 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 "Listeners Vs Filters" Watch "Listeners Vs Filters" New topic

Listeners Vs Filters

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
It says that we can use filters to track the user request but all these we can do by listeners also so why filters ?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
What kind of listener would you use that gets activated by an incoming request?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

You may use ServletRequestListener.

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

With filters you can use the Chain of Responsibility pattern whereas I do not think this could be accomplished with the listener.

The filters' implementation of Chain of Responsibility allows you to wrap the request or response using the Decorator pattern. This is something else that the listener does not allow you to do.

Oh, and I think the listener can only be run when a request is created or destroyed. This means it can not be configured to run during a forwarding of a request - but as I recall it is possible to configure listeners to run on any of the different kinds of dispatching on a request.

A good workman is known by his tools.
I agree. Here's the link:
subject: Listeners Vs Filters
jQuery in Action, 3rd edition