• 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 mapping to servlets

 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone
I'm having a problem figuring out how to get a filter to map to a specific servlet. I have the following structure in my web app:

My web.xml file looks like this:

when I use the url-pattern (/*) in the filter-mapping it works fine, however if I use anythig else it doesn't work. I've tried:
<servlet-name>WelcomeServlet</servlet-name>
<servlet-name>/WelcomeServlet</servlet-name>
<servlet-name>/*</servlet-name>
<url-pattern>WelcomeServlet</url-pattern>
<url-pattern>/WelcomeServlet</url-pattern>
None of them work. Am I declaring something wrong? Anyone have a clue?
Thanks
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is most likely due to the fact that your servlet has not been mapped to a URL. Filters require that the requested URL be valid, so if the URL you request has not been mapped, the FilterChain will not be constructed.
Try mapping the Servlet to a URL, map the Filter to the same URL and go from there.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Ken, unfortunately it didn't work
any other ideas?
anyone?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen reports (but don't know the specifics off-hand) of web containers having problems with classes in the default package.
I'd suggest placing your servlet in a package (good practice, in any case) and see if you have better luck.
hth,
bear
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear
I had already thought of that and tried it and no luck there either.
My deployment descriptor looks like this:

The only way I can get it to go through the filter is to use the url-pattern with a value of /*
I'm using tomcat 4.1.
[ September 25, 2002: Message edited by: Dave Vick ]
 
Ken Robinson
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should also work if the FilterMapping is the same as the ServletMapping.
The spec dictates the rules for mapping and are as follows:
1. The container will try to find an exact match of the path of the request to the
path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix: This is done
by stepping down the path tree a directory at a time, using the �/� character as
a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the serv-let
container will try to match a servlet that handles requests for the extension.
An extension is defined as the part of the last segment after the last �.� char-acter.
4. If neither of the previous three rules result in a servlet match, the container will
attempt to serve content appropriate for the resource requested. If a "default"
servlet is defined for the application, it will be used.

These are directly from the 2.3 spec. Of course, Filters are still new, so there may be issues. Play with the mapping and see what works for the server you are using. I've played with it in Tomcat and had no problems, but I only tried a few specific test.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ken,
I've come to the onclusion that it is me, or my tomcat install, that is the issue. I've searched the web and can't find any other references to others having problems like this - so it must be me.
I might do a new install of tomecat and see what that gets me.
Thanks again Ken and Bear
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic