Tag Archives: jsp

Spring MVC 3: Getting a 404 for a mapped static resource

18 Aug

Spring Mvc 3 has introduced a simpler way to map static resources so that you don’t have to handle requests for static content yourself. In it’s simplest form, it looks something like this:

<mvc:resources mapping="/resources/**" location="/resources/" />

Full details in the Spring 3 Documentation: http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html#mvc-static-resources.

It looks like it should be simple to implement, and for the most part it is; however, I did have a bit of trouble figuring out why I was getting a 404 error when trying to access mystylesheet.less (Less Css is awesome, check it out here: http://lesscss.org/).

Turns out that because I was using a file with an extension that you wouldn’t normally be considered as a web resource, I had to add the following configuration to my web.xml:

<mime-mapping>
<extension>less</extension>
<mime-type>text/css</mime-type>
</mime-mapping>

Probably a no-brainer for most, but I’m relatively new to the world of jsp and I would have found a post like this useful, so here I am sharing my new found knowledge!