• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confirmation Required(About Filter Sequence)

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi
i have declared filter in web.xml as shown below
filter1 is declared first and filter2 is declared 2nd.
So this means that filter2 will be executed before filter1 because
filter2 will be at top of the stack.
In short filter2 will be executed first and filter1 will be executed second.
please correct me if i am wrong.

Thanks
 
Viji Elango
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are wrong. The order of execution of the filters is the order in which they appear in the deployment descriptor.

Regards,
Viji.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then why filter2 gets executed first and filter1 gets executed 2nd for
/filter.do url pattern.
 
Viji Elango
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. When the servlet container receives a request, it finds all the filter mappings with a <b> URL pattern </b> that matches the request URI. This becomes the first set of filters in the filter chain.
2. Next, it finds all the filter mappings with a <b> servlet name </b> that matches the request URI. This becomes the second set of filters in the filter chain.
3. In both sets, the order of the filters is <b> the order in which they appear in the deployment descriptor. </b>

Hope this helps.

Regards,
Viji.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please can you explain how url in above web.xml matches with filter execution sequence.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set 1 is executed before Set 2 !
 
Viji Elango
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your case, you've only declared <servlet-name> to your <filter-mapping>.
You've not declared any <url-pattern> for the <filter-mapping>.
Hence it is very straight forward. Filter1 will be called first followed by Filter2.

Just try out the urls given in the HFSJ book (Filters Chapter). Then you'll get a clear picture.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Viji now i got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic