• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to understand the container rules for ordering filters?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Frits.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic