aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes [Solved][HFSJ] Filter Preferences 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 "[Solved][HFSJ] Filter Preferences" Watch "[Solved][HFSJ] Filter Preferences" New topic
Author

[Solved][HFSJ] Filter Preferences

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
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

Joined: Jun 06, 2007
Posts: 2716
    
    6

This question does not relate to JSP, I'll move it to an appropriate forum for you.


SCJP, SCWCD.
|Asking Good Questions|
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

5 cannot be after 2, because all matching url-pattern come first.


[My Blog]
All roads lead to JavaRanch
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Aug 16, 2007
Posts: 1374
Oh my Bad.... Now I got it ... I should have read the rules carefully. Sorry Christophe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Solved][HFSJ] Filter Preferences