• 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

Filter doubt

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this statement correct?

Filter associated with named servlet are invoked in order defined in DD?
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Salil,

this is correct! The filters that match a given URI are applied in the order they appear in your web.xml DD.

Marco
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No not correct it is decided on the bais of url-pattern or servlet-name in filter-mapping element in DD, where url-pattern matching filters are always given higher precedence than servlet-name mapping if both refer
to used for servlet.
 
Salil Dhawan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem is that i know that url-pattern comes before servlet name but i guess way option is structured is confusing.I am not sure if its referring only to servlet only ( and not url patterns at all).

Such structuring of questions sometimes make you do mistake even when you know the concept
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, sorry. My answer was a little bit too short. The order of filters in the same chain corresponds to the order the filters appear in the DD.
The chain of a filter is evaluated by means of the mappings...

Unfortunately this article from Sun is the only one I've found at the moment which more or less describes the behavior of filters.

If you have it at hand: "Head First - Servlets & JSPs" describes this a lot better!

Marco
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can declare a mapping to a URL or a servlet-name to a filter.

The container first locates the filters with a matching URL in the order the filters are declared in the Deployment Descriptor. Next the container does the same with a matching servlet-name.

This is sounds also logical to me, because a servlet-name will be in the most times more specific than a url. An url could relate to different servlets.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am agree with Remko.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The container first locates the filters with a matching URL in the order the filters are declared in the Deployment Descriptor. Next the container does the same with a matching servlet-name.



Where does it appear in the espec?


According the HFJS:

Filter associated with named servlet are invoked in order defined in DD, regardless if I used servlet-name or url-mapping.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The filters execute in the order they are declared in web.xml or generically speaking DD.
 
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
"Vikrant",
You have already been warned several times about the Naming Policy. Please read it carefully and change your name accordingly (you need to set both first and last names). Be careful that your account may be closed if you do not make the necessary changes. Thank you.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

First, all matching filters will run for <filter-mappings> with <url-pattern> matches, in order of <filter-mapping> declaration.

Second, all matching filters will run for <filter-mappings> with <servlet-name> matches, in order of <filter-mapping> declaration.

I am posting this after trying this with some examples....
 
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic