Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applying more than One Filters

 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to filter a Servlet but I don't know how can I apply more than one filter for a servlet. I have attached an image for the same.
Here filter F1 is mapped to servlets S1, S2, and S3, filter F2 is mapped to servlet S2, and filter F3 is mapped to servlets S1 and S2.

I found this in Sun Filter Tutotial

Can anyone clarify this through code or diagram for better understanding?

Thanks in advance !

Fig26.gif
[Thumbnail for Fig26.gif]
Filter Condition
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You apply filters via configuration in your web.xml file by URL patterns or servlet names.


See section 6.2.4 in the servlet spec for the rules used in determining the chaining order.

Here is an excerpt:

The order the container uses in building the chain of filters to be applied for a
particular request URI is as follows:

1. First, the <url-pattern> matching filter mappings in the same order that these
elements appear in the deployment descriptor.

2. Next, the <servlet-name> matching filter mappings in the same order that
these elements appear in the deployment descriptor.
If a filter mapping contains both <servlet-name> and <url-pattern>, the
container must expand the filter mapping into multiple filter mappings (one for
each <servlet-name> and <url-pattern>), preserving the order of the <servletname>
and <url-pattern> elements. For example, the following filter mapping:
 
Kris Schneider
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might also help to look at the actual schema for web.xml to see how the filter-mapping element is defined: http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

I've attached an image produced by JDeveloper to help visualize the structure...
web-app_2_5_filter-mapping.png
[Thumbnail for web-app_2_5_filter-mapping.png]
filter-mapping element for web.xml
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Kris and Ben
It is now clear to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic