• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filters

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in "Head First Servlets and JSP" that if container cant find the right resource for the request, the filter is never invoked. Here by "right resource" do we mean servlet/jsp or even welcome file?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi MaheshS,

A filter always works on either a:
  • Dynamic web-resource, i.e. Servlet, matched by a servlet name
  • Static web-resource matched by an URL-pattern

  • If the filter-mapping doesn't match a servlet name or a static web-resource ( that means the url-pattern doesn't make a match), then the filter is never invoked
    If you have a default mapping '/' in the <url-pattern> of a <filter-mapping>, then the filter is never invoked ('/' is only used for the default servlet)

    But if you have a mapping of '/*' (meaning all the requests) in the <url-pattern> of a <filter-mapping>, the filter is always invoked, but it can still fail with a "resource unavailable".

    Regards,
    Frits
     
    MaheshS Kumbhar
    Ranch Hand
    Posts: 188
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Frits
    But I didnt get the term default servlet.
    ('/' is only used for the default servlet).
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Saloon Keeper
    Pie
    Posts: 2536
    113
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    have a look at the specification Servlet 2.4, section SRV.11.1 (and maybe SRV.9.10 about welcome files)

    Regards,
    Frits
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic