• Post Reply Bookmark Topic Watch Topic
  • New Topic

filter mapping to servlets  RSS feed

 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • 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
 
Ken Robinson
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the reply Ken, unfortunately it didn't work
any other ideas?
anyone?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!