I am developing a webapp using Spring MVC 3 and have the DispatcherServlet
catching all requests to \'/\' like so (web.xml):
I know there are a few configurations to use the static contents, but my solution is that I just create a bulk web-application folder within your tomcat. This "bulk webapp" is only serving all the static-contents without serving apps. This is pain-free and easy solution for serving static contents to your actual spring webapp.
For example, I'm using two webapp folders on my tomcat.
If I want to use javascript, I simply add the URI for my javascript file.
EX> /resources/path/to/js/myjavascript.js
For static images, I'm using the same method.
EX> /resources/path/to/img/myimg.jpg
Last, I put "security-constraint" on my tomcat to block the access to actual directory. I put "nobody" user-roll to the constraint so that the page generates "403 forbidden error" when people tried to access the static-contents path.
So far it works very well for me. I also noticed that many popular websites like Amazon, Twitter, and Facebook they are using different URI for serving static-contents. To find out this, just right click on any static content and check their URI.