Imagine that you want Spring MVC's DispatcherServlet
to handle all URLs in your application excluding the URLs of static content. If you try to do it directly with <url-pattern>/</url-pattern>
, this mapping will take precedence over the static content.
With rewrite filter you can specify exclusions for the static content, like this:
<urlrewrite default-match-type="wildcard">
<rule>
<from>/staticContentHere/**</from>
<to>/staticContentHere/$1</to>
</rule>
<rule>
<from>/**</from>
<to>/app/$1</to>
</rule>
</urlrewrite>
EDIT:
Note that since Spring 3.0.4 there is a <mvc:resources />
declaration. With this declaration, DispatcherServlet
will serve static content from the /resources
subfolder of your webapp, so rewriting will not be needed (see http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/).