【发布时间】:2013-06-20 23:08:43
【问题描述】:
我已经尝试了很长时间,现在尝试在我的网站上使用我在 Spring 中创建的图像。 当我在 stackoverflow 上谷歌/搜索时,它说如果我想在 .jsp 中使用它:
<img src="<c:url value='resources/face.jpg'/>"/>
我需要在 web.xml 文件中实现这个:
<!--<servlet-mapping>-->
<!--<servlet-name>default</servlet-name>-->
<!--<url-pattern>*.jpg</url-pattern>-->
<!--</servlet-mapping>-->
和
<servlet>
<servlet-name>restservices</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我在 rest-services-config.xml 中粘贴了这个:
<!-- the mvc resources tag does the magic -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/images/**" location="/images/" />
仍然无法让它工作!
我究竟做错了什么?
控制台给了我这个:method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/]
我在 \project\src\main\resources 中的资源文件夹中有图像
当我尝试打开图片时,控制台给了我这个信息(不会在网站上显示):
servlet.resource.ResourceHttpRequestHandler - No matching resource found - returning 404
感谢正手!
【问题讨论】:
-
你使用什么版本的 Spring WebMVC?
-
您的问题@benskiiii 的状态如何?你没有接受答案。您是否仍有疑问 - 您还有疑问吗?请问这种情况可以问吗?
-
我还没有尝试过你的答案,因为该项目将在今天或周一部署,我没有时间处理它。我会在今天或星期一测试您的答案后回复您。兄弟,benshii
标签: java html jsp spring-mvc jpeg