This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pno-:695 HFS&JSP Filter Sequence

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<filter-mapping>
<filter-name>Filter1</filter-name>
<url-pattern>/Recipes/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>Filter2</filter-name>
<url-pattern>/Recipes/HopsList.do</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>Filter3</filter-name>
<url-pattern>/Recipes/Add/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>Filter4</filter-name>
<url-pattern>/Recipes/Modify/ModRecipes.do</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>Filter5</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Request PathFilter Sequence
------------ ----------------
/Recipes/HopReport.do---->1,5(ok)
/Recipes/HopsList.do---->1,5,2(why not 1,2,5 )
/Recipes/Modify/ModRecipes.do---->1,5,4(why not 1,4,5 )
/HopsList.do---->5(ok)
/Recipes/Add/AddRecipes.do---->1,3,5(ok)

Filter url matching sequence is determined by sequence in DD.
i.e if two or more url matches then there sequence will be determined by sequence in DD.

I have doubt in Request Path 2nd and Request Path 3rd

For 2nd path the sequence should be 1,2,5 as per DD sequence
Same way For 3rd path the sequence should be 1,4,5 as per DD sequence

Thanks
 
aanal jethalia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for filter 2 and filter 4 instead of <url-pattern> element there is <servlet-name> element in Head First. Filter chain will have the matching url-patterns first and then the matching servlet-name.
 
Pallavi Roy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As mentioned earlier that your question is wrong copied.
Change the options to <servlet-name> <url-pattern>/Recipes/HopsList.do</url-pattern>
and <url-pattern>/Recipes/Modify/ModRecipes.do</url-pattern>.

They rule is the url mentioned is mapped to the <filter-mapping>
a) Group the matching <url-pattern> in the sequence they appear in the DD.
b) Group the matching <servlet-name> in the sequence they appear in the DD.

This rule will determine the filter sequence.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
i got it
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a age old question
filters with url-pattern are executed before serlvets
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only the order in DD matters is it?I thought its from most matching to the least say if url is like /recipes/ind/chat.do

then if there is an exact match like the one above then that will be selected first followed by /recipes/ind then /recipes then /* can anyone explain?
 
Pallavi Roy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Renuka,
The order you mention is for servlet declaration
<servlet-mapping>
<servlet-name>
<url-pattern>
</servlet-mapping>

where the order goes like 1)Exact match 2)directory match 3)/*.xyz match.

But when it comes to filters this order is not followed.
If you see the book then in the bang section you will find this note.

Best Regards,
Pallavi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic