aspose file tools*
The moose likes Servlets and the fly likes Applying more than One Filters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Applying more than One Filters" Watch "Applying more than One Filters" New topic
Author

Applying more than One Filters

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
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 !




[Thumbnail for Fig26.gif]



God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
OCPJP6
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
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...



[Thumbnail for web-app_2_5_filter-mapping.png]

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
Thanks a lot Kris and Ben
It is now clear to me.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Applying more than One Filters