• 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

[Solved][HFSJ] Filter Preferences

 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read below about filters in HFSJ Page # 710

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.


Based on that I tried to answer below question.

Question:

Here we need to determine the sequence for every request path.

I answered:____________________Correct Answer

1-5____________________ 1-5
1-2-5__________________ 1-5-2
1-4-5__________________1-5-4
5_____________________ 5
1-3-5__________________1-3-5

Here, My answers differ for 2nd and 3rd request path.

Based on the above quote and my understanding I solve like this.
First see how many patterns match with filter pattern. Put them aside. Now only those filters will be called in order they are defined.

So what's wrong?

 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question does not relate to JSP, I'll move it to an appropriate forum for you.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5 cannot be after 2, because all matching url-pattern come first.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:5 cannot be after 2, because all matching url-pattern come first.

1,2 and 5 are matching Filter for 2nd request path. Now it should follow the order in which they are defined. And the order is Filter 1 Filter 2 and Filter 5.
Ain't I correct?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look carefully how the declaration for 1,5 differs from 2. 1 and 5 use the "url-pattern". 2 uses the "servlet-name". All matching "url-pattern" come before any matching "servlet-name". So, 2 cannot be called before 5. 1 and 5 are both "url-pattern", so they wil be called in the order they have been declared. So, 1 first, then 5. As a result, filters will be called in the following order : 1,5,2
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my Bad.... Now I got it ... I should have read the rules carefully. Sorry Christophe.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic