Spring 3 MVC资源和标签< mvc:resources/> [英] Spring 3 MVC resources and tag <mvc:resources />

查看:141
本文介绍了Spring 3 MVC资源和标签< mvc:resources/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码存在一些问题(春季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.

我试图删除mvc:resource标记,只允许mvc:default-servlet-handler>一个,给了我无限循环和stackoverflow ... o_O(

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资源和标签&lt; mvc:resources/&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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