• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter doubt

 
Salil Dhawan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this statement correct?

Filter associated with named servlet are invoked in order defined in DD?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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
 
Ravi Singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • 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.
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am agree with Remko.
 
Luis Torres
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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.
 
Vikrant Sahdev
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The filters execute in the order they are declared in web.xml or generically speaking DD.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
kamalakannan kamal
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic