• 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

Filters

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please how filters are invoked one after another how do the need to specify in web.xml.


Please correct me if i am wrong

For ex

Assume there are two filters A ,b. After b completes its process & tranfers request to servlet S. Servlet S then completes its work transfers control back to filter b, then filter A.


<filter>
<filter-name>A</filter-name>
<filter-class>class.A</filter-class>
</filter>


<filter-mapping>
<filter-name>A</filter-name>
<url-pattern>/my</url-pattern>
<filter-mapping>


<filter>
<filter-name>b</filter-name>
<filter-class>class.b</filter-class>
</filter>


<filter-mapping>
<filter-name>b</filter-name>
<url-pattern>/my</url-pattern>
</filter-mapping>


<servlet>
<servlet-name>S</servlet-name>
<servlet-class>class.S</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>S</servlet-name>
<url-pattern>/my</url-pattern>
</servlet-mapping>



Q1) Is this web.xml is correct?
Q2) Is oder is determined from DD?

Q3)How chain.doFilter() detrmines which filter to execute next?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) I'm no container but it looks ok to me. The best person to ask is your web app container.

Q2) According to the Servlet 2.4 spec, the order of the filters is by:
1 - the <url-pattern> matches in the order they appear in the DD followed by
2 - the <servlet-name> matches in the order they appear in the DD
Since your example uses the <url-pattern> for both filters, the filters will execute in the order their mappings appear in the DD. Keep in mind that the first to intercept the request/response on its way in is the last to intercept on the way out.

Q3) The container handles all that. This is often difficult for Java programmers to understand because usually we're responsible for writing 100% of everything an application accomplishes. For filters, the container controls their flow.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) Apart from an unclosed filter-mapping, but I bet this is a typo
reply
    Bookmark Topic Watch Topic
  • New Topic