Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filters

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • 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?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) Apart from an unclosed filter-mapping, but I bet this is a typo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic