Simplest example:
I have a dispatcher servlet configured to catch everything:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I have a simple test controller:
@RequestMapping("/index")
@ResponseBody
public String rootTest(){
return "Main page displayed from TestController";
}
In this test case I am adding (or removing) the following line to dispatcher-servlet.xml
:
<mvc:resources mapping="/public/**" location="/public/"/>
My lofty goal: to serve static content (images, css, js) along with my dynamic content (generated via Velocity within a Jetty servlet container, tied together with the almighty Spring).
My Dilema: When I add <mvc:resources .../>
I get a 404 for http://localhost/index
, but I can serve an image from http://localhost/public/img/42.png. If I remove <mvc:resources .../>
then http://localhost/index
works fine, but of course, how do I serve static content?
Bonus question: Why can I never have my cake and eat it too?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…