• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Applying more than One Filters

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Kris and Ben
It is now clear to me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic