How can a filter map to the root of a url? I am using Tomcat 7.0.2 and deploying the application as ROOT.war. Welcome page - sign_in.xhtml. I would like to run the filter whenever the client sends a request for the root of the site (i.e. only the domain name) or when the client requests sign_in.xhtml. Here is what I still have:
<filter> <filter-name>My filter</filter-name> <filter-class>com.myApp.myFilter</filter-class> </filter> <filter-mapping> <filter-name>My filter</filter-name> <url-pattern>/sign_in.xhtml</url-pattern> </filter-mapping>
Requests for sign_in.xhtml directly, successfully invoke the filter, but I'm not sure how to get root requests to invoke the filter. According to Servlet specification (version 3.0)
<url-pattern>/</url-pattern>
displays the servlet by default, and the empty string maps to the root. Here is the relevant section from the specification:
"Empty line (" ") is a special URL pattern that exactly matches ie requests of the form http: // host: port / /. In this case, the path information is /, and the servlet path and context path are an empty string ( "").
However, both of the following url patterns cause Tomcat to throw an exception.
<url-pattern></url-pattern> <url-pattern>""</url-pattern>
I would really appreciate it if someone could shed light on this. Thanks.
Andrew
java servlets servlet-filters url-pattern
J. Andrew Laughlin
source share