wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Configuring Filters in Tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring Filters in Tomcat 5" Watch "Configuring Filters in Tomcat 5" New topic
Author

Configuring Filters in Tomcat 5

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
I'm trying to setup a filter in my webapps web.xml file but it only seems to work with a specific filename and not the entire directory as needed.

Here's my filter element from the web.xml file.
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>net.domain.auth.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
***********************************************************
**** this works fine with 'menu.jsp' but if I change it to '*.jsp'
**** it kills the app.
***********************************************************
<url-pattern>/management/menu.jsp</url-pattern>
</filter-mapping>

Do I have the wrong syntax?
<url-pattern>/management/*.jsp</url-pattern>

Thanks,
Dave
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

You're mixing two different URL-patterns. In the Servlet Spec section SRV.11.2:

In the web application deployment descriptor, the following syntax is used
to define mappings:

� A string beginning with a �/� character and ending with a �/*� postfix
is used for path mapping.
� A string beginning with a �*.� prefix is used as an extension mapping.
� A string containing only the �/� character indicates the "default"
servlet of the application. In this case the servlet path is the request
URI minus the context path and the path info is null.
� All other strings are used for exact matches only.

The last point is the kicker. If it doesn't match any of the three patterns, it defaults to 'exact match'. So your pattern of "/management/*.jsp" would try to match a file named "*.jsp" in the /management directory. Which is not what you wanted, and it probably would break before attempting the match.

Can you use "/management/*" ?

This would have the effect of protecting all JSPs under the management directory (which is what you seem to be going for with your pattern.

Note, that would also protect *.gif and *.html (and everything else you might access that starts with /management).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuring Filters in Tomcat 5