• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Solved][HFSJ] Filter Preferences

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • 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?

 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question does not relate to JSP, I'll move it to an appropriate forum for you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Oh my Bad.... Now I got it ... I should have read the rules carefully. Sorry Christophe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic