• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confirmation Required(About Filter Sequence)

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please can you explain how url in above web.xml matches with filter execution sequence.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set 1 is executed before Set 2 !
 
Viji Elango
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Viji now i got it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic