春季:DispatcherServlet和静态内容 [英] Spring: DispatcherServlet and static content
问题描述
在我的Spring Web应用程序中,我已将/app/*
映射到调度程序servlet.在该场景中将images
,.js
,.css
之类的静态内容与调度程序分开的最佳方法是什么?
In my Spring web-app i have mapped /app/*
to dispatcher servlet. What is the best approach in that scenerio to separate a static content like images
, .js
, .css
from dispatcher ?
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
例如,当我打开URL:http://server/context/app/users
且在users.jsp上具有<img src="images/test.png"/>
时,我没有图像,因为http://server/conext/app/users/images/test.png
不是正确的URL.
For example, when i open url: http://server/context/app/users
and on users.jsp have <img src="images/test.png"/>
i get no image because http://server/conext/app/users/images/test.png
is not a right url.
现在,我使用绝对路径,例如:<img src="/context/images/test.png"/>
,但是它会使JSP代码稍微复杂一些,并且搜索起来会更好.
Now i use absolute path like: <img src="/context/images/test.png"/>
but it complicates JSP code a little and searching something better.
推荐答案
您可以使用<mvc:resources>
告诉DispatcherServlet
某些路径应作为静态资源进行处理.
You can use <mvc:resources>
to tell the DispatcherServlet
that certain paths should be handles as static resources.
请参见如何配置Spring 3.0.x手册的15.12.4节.
这篇关于春季:DispatcherServlet和静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!