Spring MVC静态资源映射 [英] Spring MVC Static Resource Mapping

查看:111
本文介绍了Spring MVC静态资源映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下servlet映射-

I have the following servlet mapping present -

  <!--  Mapping Static Resources -->
     <mvc:resources mapping="/css/**" location="/resources/css/" />
     <mvc:resources mapping="/js/**" location="/resources/js/" />
     <mvc:resources mapping="/images/**" location="/resources/images/" />

我在html中的图像链接是"/images/folder/imageName.jpg"-这些图像使我得到404,而如果将链接更改为"/images/imageName.jpg"并将图像移至images文件夹会为我获取图像.

My image link in the html is "/images/folder/imageName.jpg" - These images get me a 404 whereas if the change the link to "/images/imageName.jpg" and move the image to directly under the images folder it gets me the image.

我是否需要以任何方式修改我的servlet映射以考虑到层次结构?

Do I need to modify my servlet mapping in any way to take into account the hierarchical structure?

推荐答案

您需要修改指向图像的链接.当你写

You need to modify links to the images. When you write

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

然后将您对/resources/images的HTTP请求转换为服务器上的webapp/images文件夹.因此,在html中,您应该具有以下内容:

Then your HTTP requests to /resources/images are translated to webapp/images folder on the server. So in the html you should have something like this:

<img src="<spring:url value='/resources/images/logo.png'/>"

这篇关于Spring MVC静态资源映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆