wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Confirmation Required(About Filter Sequence) 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 "Confirmation Required(About Filter Sequence)" Watch "Confirmation Required(About Filter Sequence)" New topic
Author

Confirmation Required(About Filter Sequence)

Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643

hi
i have declared filter in web.xml as shown below
filter1 is declared first and filter2 is declared 2nd.
So this means that filter2 will be executed before filter1 because
filter2 will be at top of the stack.
In short filter2 will be executed first and filter1 will be executed second.
please correct me if i am wrong.

Thanks
Viji Elango
Ranch Hand

Joined: Apr 25, 2006
Posts: 36
You are wrong. The order of execution of the filters is the order in which they appear in the deployment descriptor.

Regards,
Viji.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
Then why filter2 gets executed first and filter1 gets executed 2nd for
/filter.do url pattern.
Viji Elango
Ranch Hand

Joined: Apr 25, 2006
Posts: 36
1. When the servlet container receives a request, it finds all the filter mappings with a <b> URL pattern </b> that matches the request URI. This becomes the first set of filters in the filter chain.
2. Next, it finds all the filter mappings with a <b> servlet name </b> that matches the request URI. This becomes the second set of filters in the filter chain.
3. In both sets, the order of the filters is <b> the order in which they appear in the deployment descriptor. </b>

Hope this helps.

Regards,
Viji.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
please can you explain how url in above web.xml matches with filter execution sequence.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Set 1 is executed before Set 2 !


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.
Viji Elango
Ranch Hand

Joined: Apr 25, 2006
Posts: 36
In your case, you've only declared <servlet-name> to your <filter-mapping>.
You've not declared any <url-pattern> for the <filter-mapping>.
Hence it is very straight forward. Filter1 will be called first followed by Filter2.

Just try out the urls given in the HFSJ book (Filters Chapter). Then you'll get a clear picture.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
Thanks Viji now i got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confirmation Required(About Filter Sequence)
 
Similar Threads
Servlet Filter chain construction order
order of filter mapping
Filters chain
unable to understand filter execution sequence
filter-mapping doubt??