• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not able to understand the container rules for ordering filters?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot Frits.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic