Spring 3 MVC 资源和标签 <mvc:resources/> [英] Spring 3 MVC resources and tag <mvc:resources />
问题描述
我在使用标签时遇到了一些问题(Spring 3.0.5).我想向我的 Web 应用程序添加图像,但它不起作用.
I'm having some problems with the tag (Spring 3.0.5). I want to add images to my web application, but it doesnt work.
这是我的 bean 配置的一部分:
Here is part of my beans config:
<mvc:annotation-driven/>
<mvc:default-servlet-handler default-servlet-name="ideafactory"/>
<mvc:resources mapping="/resources/**" location="/, classpath:/WEB-INF/public-resources/" cache-period="10000" />
尝试在jsp文件中添加图片:
Trying to add an image in a jsp file:
<img src="<c:url value="/resources/logo.png" />" alt="Idea Factory" />
首先,我真的不知道在哪里存储资源(src/main/resources/public-resources?src/main/webapp/WEB-INF/public-resources?).其次,这个配置不起作用,我看不到图像.怎么了?
First of all, I don't know really where to store the resources (src/main/resources/public-resources? src/main/webapp/WEB-INF/public-resources?). Secondly, this config does not work, I can't see the image. What's wrong?
谢谢!
此处给出的解决方案:Spring Tomcat 和静态资源和 mvc:资源 也不起作用...添加失败.
the solution given here: Spring Tomcat and static resources and mvc:resources doesn't work either... Added without success.
编辑 2:我试图删除 mvc:resource 标签,只让 mvc:default-servlet-handler> 一个,给了我无限循环和 stackoverflow...o_O (使用 Spring 3 提供静态内容)
EDIT 2: I tried to remove the mvc:resource tag and let only the mvc:default-servlet-handler> one, gave me infinite loop and stackoverflow... o_O (Serving static content with Spring 3)
推荐答案
发现错误:
最终的 xxx-servlet.xml 配置:
Final xxx-servlet.xml config:
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
src/webapp/resources/logo.png 中的图片
Image in src/webapp/resources/logo.png
有效!
这篇关于Spring 3 MVC 资源和标签 <mvc:resources/>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!