jQuery in Action, 3rd edition
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter Chaning Query..! 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 Chaning Query..!" Watch "Filter Chaning Query..!" New topic

Filter Chaning Query..!

Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153

Can any one tell me the Filter ordering Sequence Fundamental. I did not understand It. I did not understand the Question and Answer Mentioned on Page 695 of hfsj.

Here's the Question :






Request Path


Filter Sequence


Can Any Body Please Explain me in Detail the Sequencing on this Filters for all 5 request Paths?


Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4
KRK Gowda
Ranch Hand

Joined: Nov 02, 2004
Posts: 132
Hi Nilesh,
concept of order in which filters are invoked is clear in HFJS.
order of filters is based on two conditions :
first, container will consider filters in the order they are declared in DD.
second, container will put the filters that are declared with url pattern tag first into queue. then it will consider filters for specific match.
in the problem mentioned above, when container receive request for /Recipes/HopsReport.do, container will consider all filters whose url-patterns match with the requested resource. i.e. fillter 1 and filter 5. when container traverse through DD, it encounter filter 1 first. so filter 1 will be executed first.
consider, /Recipes/HopsList.do for this request, 3 filters do have match. filter 1, filter 2 and filter 5.
container will traverse through DD for matching url pattern and it finds filter 1 and filter 5. so these 2 are added into queue. againg container checks for specific match by comparing servlet name tag. it finds specific match with filter 2. filter 2 will be added to queue.
hence, the order in which filters are executed is filter 1, filter 5 and filter 2.

hope it will be clear now.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
to make things simple, remember this -

filters are executed before the servlets
or to be more precise,
filters with <url-patterns> in their mapping are executed before those with a <servlet-name> in the mapping.

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
K Thapa

Joined: Sep 02, 2004
Posts: 8
I am a little confused here. Is Filter Mapping mechanism different than the servlet mapping ?

Once it finds all the filters matching the url-pattern first, shouldn't it go by the exact match first ( the longest directory mapping) instead of ordering in the DD?
In /Recipes/Modify/ModRecipes.do,
it finds Filters 1, 5 and 4.
Because 4 is the exact match, that should be called first and then 1 and then 5.
So the ordering should be 4,1,5 instead of 1,5,4

Any thoughts? or is it yet another notorious Sun discrepencies?
I agree. Here's the link: http://aspose.com/file-tools
subject: Filter Chaning Query..!
It's not a secret anymore!