• 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

Filters and url-pattern confusion

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello group,

I am using David Bridgewater's book to prepare for the exam. One of the Self Test answers claims that the url-pattern "/" is a "catch all" pattern answer to Chapter 4 Question 5). The same is claimed on page 198 about the pattern used for a LogFilter class.

However, when I try it out in a filter-mapping, the pattern "/" only works when exactly matched. In the servlet specs I can only find that the url-pattern work the same as for servlets.

For servlets the rules are as follows (please, correct me if I am wrong):

Take the request URI and strip the context path. On what is left, do the following:

  • Try find an exact match among the url-patterns that contain no '*'.
  • If not found: try to match among the url-patterns that end in '/*' (e.g, /*, /somedir/*, /somedir/somesubdir/*) If multiple matches are found, take the longest.
  • If not found: try to match among the url-patterns that start with '*.' (e.g, *.jsp, *.html)
  • If still not found, use url-pattern '/' if present.


  • The goal is to find exactly one servlet. However, with filters all the matching filters must be executed. If I try this out in Tomcat 5.5.17, this is indeed the case, but the "default" ('/') is apparently not considered a match, as the mapped filter is only executed if I request a URL of the form
    <context path>/ (e.g. http://localhost:8084/MyApp/).

    So, am I forgetting something here or should I be sending an erratum to the author?

    Thanks for any help, regards,

    Jan van Mansum.
     
    pie sneak
    Posts: 4727
    Mac VI Editor Ruby
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    My understanding is that /* is the catch-all. I would expect / with no star would behave exactly as you said.

    I don't think the Bridgewater book has an official errata unfortunately.
     
    Jan van Mansum
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    He does have an errata zip file on his home page. I'll be emailing this one to him + some others that I found.
    [ November 13, 2007: Message edited by: Jan van Mansum ]
     
    Marc Peabody
    pie sneak
    Posts: 4727
    Mac VI Editor Ruby
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Oh, cool.

    And somebody already added the errata link to ScwcdLinks.

    Ironic I didn't look there first. :roll:
    reply
      Bookmark Topic Watch Topic
    • New Topic