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

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

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