静态资源的URI中的上下文路径,我真的需要指定它吗?
我有一个简单的网络应用程序
webapp static images - a.gif pages - test.html WEB-INF pages - test.jsp
在test.html中,有
问题是,在我将uri更改为之前,图像不会显示
但是我在URI上加载test.html
http://server/web app name/static/pages/test.html
我在我的web.xml中配置了静态资源映射,如下所示。
springWeb org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:applicationContext-web.xml 1 springWeb / resourceServlet org.springframework.js.resource.ResourceServlet 1 resourceServlet /static/*
我错过了什么吗? 我确实希望在DEV阶段将这些静态资源保留在应用程序中,而不是将它们移动到HTTP服务器。
非常感谢。
出于这个原因,最好使用spring:url标记或JSTL c:url标记来包装HTML中的URL。 这些标签将自动添加上下文路径。
例如:
或者,您可以在开发中使用“”的上下文路径。 那样你的url就会与生产相匹配。 对于每个servlet容器,这样做的方式是不同的 – 例如,对于Tomcat,您可以将应用程序部署到webapps / ROOT。
使其更通用的一种方法是使用
如果您知道目录结构,则可以使用相对URL,例如
static/images/a.gif ../static/images/a.gif