[英]How can I load an image from my resources/images folder in spring mvc?
I am trying to load 2 images from my resources/images folder and display them on my index.jsp: 我正在尝试从我的resources / images文件夹加载2张图像,并将它们显示在index.jsp上:
<img src="<c:url value='/resources/images/harry_potter.jpg'/>"/>
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/harry_potter.jpg">
<img src="<c:url value='/resources/images/hp.jpg'/>"/>
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/hp.jpg">
When I load the page images don't appear, instead there are image icons. 当我加载页面时,图像不会出现,而是有图像图标。 As you've seen in my index.jsp, I've tried 2 different methods for loading an image
如您在index.jsp中所见,我尝试了2种不同的方法来加载图像
I have an application.xml page and a dispatcher-servlet page.xml 我有一个application.xml页面和一个dispatcher-servlet page.xml
In each file I have tried putting this under the context:component-scan 在每个文件中,我都尝试将其放在上下文中:component-scan
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
but I still do not see my images on the index page. 但我仍然无法在索引页面上看到我的图像。 Does anyone know why this isn't showing
有谁知道为什么没有显示
My File Structure for reference: 我的文件结构供参考:
File Image View 文件图像视图
In my web.xml for reference: 在我的web.xml中供参考:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Console for reference 控制台供参考
Console Image View 控制台映像视图
Try this please, may work;) 请尝试这个,可能会起作用;)
Change 更改
<mvc:resources mapping="/resources/**" location="/resources/" />
to 至
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.