I am developing a webapp using Spring MVC 3 and have the DispatcherServlet
catching all requests to \'/\' like so (web.xml):
I've just been grappling with this issue in Spring MVC 3.0 and I initially went with the UrlRewriteFilter option. However I was not happy with this solution as it "didn't feel right" (I'm not the only one - see the link above to the Spring Forums where the word "hack" appears a few times).
So I came up with a similar solution to "Unknown (Google)" above but borrowed the idea of having all static content served from /static/ (taken from the Spring Roo version of the Pet Store app). The "default" servlet did not work for me but the Spring Webflow ResourceServlet did (also taken from Spring Roo generated app).
Web.xml:
mainDispatcher
org.springframework.web.servlet.DispatcherServlet
2
Resource Servlet
org.springframework.js.resource.ResourceServlet
1
mainDispatcher
/
Resource Servlet
/static/*
The only change I made to JSPs was to add the /static/ path to URLs for CSS, JS and images. E.g. "${pageContext.request.contextPath}/static/css/screen.css".
for Maven users the dependency for "org.springframework.js.resource.ResourceServlet" is:
org.springframework.webflow
org.springframework.js
2.0.8.RELEASE