aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter doubt 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 "Filter doubt" Watch "Filter doubt" New topic
Author

Filter doubt

Salil Dhawan
Greenhorn

Joined: Sep 18, 2006
Posts: 16
Is this statement correct?

Filter associated with named servlet are invoked in order defined in DD?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Salil,

this is correct! The filters that match a given URI are applied in the order they appear in your web.xml DD.

Marco
Ravi Singh
Greenhorn

Joined: Jun 02, 2008
Posts: 26
No not correct it is decided on the bais of url-pattern or servlet-name in filter-mapping element in DD, where url-pattern matching filters are always given higher precedence than servlet-name mapping if both refer
to used for servlet.
Salil Dhawan
Greenhorn

Joined: Sep 18, 2006
Posts: 16
Problem is that i know that url-pattern comes before servlet name but i guess way option is structured is confusing.I am not sure if its referring only to servlet only ( and not url patterns at all).

Such structuring of questions sometimes make you do mistake even when you know the concept
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

OK, sorry. My answer was a little bit too short. The order of filters in the same chain corresponds to the order the filters appear in the DD.
The chain of a filter is evaluated by means of the mappings...

Unfortunately this article from Sun is the only one I've found at the moment which more or less describes the behavior of filters.

If you have it at hand: "Head First - Servlets & JSPs" describes this a lot better!

Marco
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
You can declare a mapping to a URL or a servlet-name to a filter.

The container first locates the filters with a matching URL in the order the filters are declared in the Deployment Descriptor. Next the container does the same with a matching servlet-name.

This is sounds also logical to me, because a servlet-name will be in the most times more specific than a url. An url could relate to different servlets.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Bk Jacky
Ranch Hand

Joined: Jun 11, 2005
Posts: 74
I am agree with Remko.


SCJP1.4<br />SCWCD1.5<br />"Nothing is impossible"
Luis Torres
Greenhorn

Joined: May 02, 2008
Posts: 20
The container first locates the filters with a matching URL in the order the filters are declared in the Deployment Descriptor. Next the container does the same with a matching servlet-name.


Where does it appear in the espec?


According the HFJS:

Filter associated with named servlet are invoked in order defined in DD, regardless if I used servlet-name or url-mapping.


SCJP5 90%
Vikrant Sahdev
Ranch Hand

Joined: May 31, 2007
Posts: 58
The filters execute in the order they are declared in web.xml or generically speaking DD.


Coming soon... www.javatales.com
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

"Vikrant",
You have already been warned several times about the Naming Policy. Please read it carefully and change your name accordingly (you need to set both first and last names). Be careful that your account may be closed if you do not make the necessary changes. Thank you.


[My Blog]
All roads lead to JavaRanch
kamalakannan kamal
Ranch Hand

Joined: May 19, 2008
Posts: 32
Hi All,

First, all matching filters will run for <filter-mappings> with <url-pattern> matches, in order of <filter-mapping> declaration.

Second, all matching filters will run for <filter-mappings> with <servlet-name> matches, in order of <filter-mapping> declaration.

I am posting this after trying this with some examples....
 
Consider Paul's rocket mass heater.
 
subject: Filter doubt