File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes not able to understand the container rules for ordering 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 "not able to understand the container rules for ordering filters?" Watch "not able to understand the container rules for ordering filters?" New topic
Author

not able to understand the container rules for ordering filters?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

i'm not able to understand the part from the hfsj book where the ordering of filters is explained. for reference the page no. is 710. following is an excerpt which i couldnt understand

IMPORTANT: The Container’s rules for ordering filters:
When more than one filter is mapped to a given resource, the Container uses the following rules:
1) ALL filters with matching URL patterns are located first. This is NOT the same as the URL mapping rules the Container uses to choose the “winner” when a client makes a request for a resource, because ALL filters that match will be placed in the chain!! Filters with matching URL patterns are placed in the chain in the order in which they are declared in the DD.
2) Once all filters with matching URLs are placed in the chain, the Container does the same thing with filters that have a matching <servlet-name> in the DD.


specifically i couldnt understand the 2nd point. please explain it with a simple example ?

Regards
Gurpreet
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

Hi,

Let's explain it with an example where we have a Servlet (e.g. FilterServlet) with the following mapping:

We can now attach filters on the basis of the url-pattern, for example: http://localhost:8080/WebAppRoot/filter/*, or we can attach a filter on the Servlet name (FilterServlet). If we have the following filters defined in our web.xml:

If we have deployed our web app and type in the following URL: http://localhost:8080/WebAppRoot/filter/FilterServlet

We will see the following execution order (where the last Sysem.out is from the FilterServlet itself)
filter.FilterOneURL
filter.FilterTwoURL
filter.FilterOneName
filter.FilterTwoName
nl.servlet.FilterServlet

You can see that the filters with a matching Servlet-name are invoked later than the ones on the basis of the URL-pattern.

Regards,
Frits
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Thanks alot Frits.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not able to understand the container rules for ordering filters?