Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in HFSJ sharpen pencil page 695

 
joko mujoko
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ, page 695 , sharpen pencil , it wrote

<filter-mapping>
<filter-name>Filter1</filter-name>
<servlet-name>/Recipes/*</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Filter2</filter-name>
<servlet-name>/Recipes/HopsList.do</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Filter3</filter-name>
<servlet-name>/Recipes/Add/*</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Filter4</filter-name>
<servlet-name>/Recipes/Modify/ModRecipes.do</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Filter5</filter-name>
<servlet-name>/*</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Filter5</filter-name>
<servlet-name>/Recipes/*</servlet-name>
</filter-mapping>

with request path a./Recipes/HopsReport.do
b./Recipes/HopsList.do
c./Recipes/Modify/ModRecipes.do
d./HopsList.do
b./Recipes/Add/AddRecipes.do

the answer wrote for chain wrote
a.Filters: 1,5
b.Filters: 1,5,2
c.Filters: 1,5,4
d.Filters: 5
e.Filters: 1,3,5


in my opinion should be...
a.Filters: 1,5
b.Filters: 2,1,5
c.Filters: 4,1,5
d.Filters: 5
e.Filters: 3,1,5

the different si just at url that match 3 url
how to chain more then 3 url that match, its look not the same rule as DD url pattern (url winner)?




Joko
 
Cai DongShan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have book on hand. The element you typed is wrong. Please check.

<servlet-name>/Recipes/*</servlet-name>
should be <url-pattern>/Recipes/*</url-pattern>

The answer is based on the sequence of the filter mapping: match URL pattern first, and then servlet name.
 
joko mujoko
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right Cai Dong Shan,

the book write <url-pattern> not <servlet-name>, but so Still sam question , how is the chain if the filter above change from <url-pattern> to <servlet-name> for the a,b,c,d url ?

Joko
 
Krishna Latha Grandhi
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am also having the same doubt...
please clarify...


Regards,
Hari Krishna.
 
Cai DongShan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We take b./Recipes/HopsList.do for example

1. Match URL pattern with the sequence of the filter list, only two are found, filter1 and then filter5.
"/*" means all the servlets under application root and its subdirectories

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

2. Match servlet name with the sequence of the filter list, only one is found, filter2.

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

So the answer is 1,5,2

Does it clear your query?
 
joko mujoko
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Cai DongShan...

Thats clear enought,The conclusion is, the rule no.
1. Match URL pattern with the sequence of the filter list, only two are found, filter1 and then filter5.
"/*" means all the servlets under application root and its subdirectories

and the chain of this following the rule of winner like in Deployment Descriptor

2. Match servlet name with the sequence of the filter list, only one is found, filter2.

its just suposse to match just one Servlet


ones again thanks alot Cai DongShan, its helper


Joko
 
Reshma Shanbhag
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
joko mujoko,

Good that you got this doubt cleared from javaranch community. I see a duplicate post for same question from you, i undertand we all want our answers soon, even i do nothing wrong in that, but it would nice of you if you request and get the one of the topic closed, helps save time for other people who answer.

Thanks,
Reshma
[ June 03, 2006: Message edited by: Reshma Pai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic