Often when working with
Spring Web MVC mappings I want all calls to a certain extension handled by a generic resolver, i.e. mapping "*.html" to corresponding "*.jsp" entries in WEB-INF. This is easily done using
UrlFilenameViewController which automatically passes the parsed filename to the view resolver.
Use the following XML for the mapper, resolver, and controller in dispatcher-servlet.xml:
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="**/*.html">filenameController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean name="filenameController"
class="org.springframework.web.servlet.mvc.UrlFilenameViewController"
/>
The
urlMapping
bean as configured maps every url that matches
<any directory>/<any filename>.html
to
filenameController
, defined as a
UrlFilenameViewController
, which simply strips off any leading cruft and the extension. The output is chained to the
viewResolver
bean which resolves the request to
/WEB-INF/jsp/<any directory>/<any filename>.jsp
.