[英]Spring 3.1: Getting the <mvc:resources To Work
我是Spring的新手。 我正在学习Spring 3.1。 我正在使用《春季行动》(第三版)一书。我在找到静态资源方面遇到了麻烦。这本书没有太多提及,所以我想知道是否能得到一些帮助。
我的“ abc.war”内部的目录结构是
WEB-INF
classes
lib
web.xml
webLogic.xml
abc-servlet.xml
css
images
js
jsp
META-INF
在我的web.xml中,我的调度程序servlet定义如下:
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
.....这是我的abc-servlet.xml文件的内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.company.abc.controllers" />
<mvc:resources mapping = "/**" location = "/"/>
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/jsp/"/>
<property name = "suffix" value = ".jsp"/>
</bean>
</beans>
我尝试将静态资源放在Webapp根目录下的“ resources”目录下,但这没什么区别(我将标记更改为<mvc:resources mapping = "/resources/**" location = "/resources"/>
时)。
基本上,abc Webapp找不到任何静态资源。
它认为图片“ header.png”位于
- htts://blah.blah.blah/images/header.png
所以图像变成空白,尽管当我将此URL粘贴到浏览器中时,我可以得到图像
- htts://blah.blah.blah/**abc**/images/header.png
我还没有找到一种使Spring在该URL中粘贴“ abc”的方法。
我是Spring的崭新白腰带,所以在帮助我解决这个问题时,婴儿说话不会被当作侮辱:)
预先感谢您的任何帮助
史蒂夫
我在Tomcat 6中尝试了我的东西,并且一切都很好(这不是WebLogic,FWIW中第一次变得更困难)。
我在Google周围找到了
http://forum.springsource.org/showthread.php?102166-mvc-resources-and-war-on-Weblogic/page2
解释了WebLogic和Spring 3. *尚未解决的问题。
作为Spring和WebLogic的新手,我大部分都不了解。
我确实注意到我所有的静态东西都会映射到
https:/blah.blah.blah/abc/images/myimage.png
但是春天会认为这是
https:/blah.blah.blah/images/myimage.png
所以,
<mvc:resources mapping = "/resources/**" location = "/resources"/>
../abc/images/myimage.png
一切正常。 遗留文件仍然使用遗留代码中的路径从战争的根源中找到静态资源,而新的Spring文件(我正在将abc从Servlet webapp逐渐转换为Spring webapp)将它们视为ell。
它是一个hack和它的粗俗,但它让我暂时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.