我是Spring的新手。我正在学习Spring 3.1。我在用《春天在行动》这本书,第三版。我很难找到静态资源。这本书没有太多关于它的内容,所以我想知道我是否可以得到一些帮助。
- 我的申请名称是"abc"
- URL类似于"https://blah.blah.blah/abc
- 我正在WebLogic 9.2上运行"abc"
- 我将"abc"部署为"abc.war"
我的"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>
我试着把我的静态资源放在Web应用程序根目录下的"resources"目录下,但这没有任何区别(当我这样做的时候,我把标签改成了<mvc:resources mapping = "/resources/**" location = "/resources"/>
)。
基本上,abc网络应用程序找不到任何静态资源。
它认为图片"header.png"在
- htts://blah.blah.blah/images/header.png
所以图像是空白的,尽管当我把这个URL粘贴到浏览器中时,我可以得到图像
- htts://blah.blah.blah/**abc**/images/header.png
不过,我还没有找到让Spring在该url中添加"abc"的方法。
我是Spring的一个全新的白带,所以用建议来帮助我解决这个问题的婴儿谈话不会被视为侮辱:)
提前感谢的任何帮助
Steve
我在Tomcat6中尝试了我的东西,结果都很好(这不是WebLogic,FWIW中第一次出现更困难的情况)。
我四处搜索,发现了这个
http://forum.springsource.org/showthread.php?102166-mvc资源与Weblogic战争/page2
解释了WebLogic和Spring3.*存在未解决的问题。
作为Spring和WebLogic的新手,我大部分都不懂。
我确实注意到我所有的静态东西都会映射到
https:/blah.blah.blah/abc/images/myimage.png
但Spring会认为这是
https:/blah.blah.blah/images/myimage.png
所以,
- 我将mvc标记设置为
<mvc:resources mapping = "/resources/**" location = "/resources"/>
- 然后,在使用spring的新文件中,我将路径更改为
../abc/images/myimage.png
一切都有效。遗留文件仍然在使用遗留代码中的路径从根目录中找到静态资源,而新的Spring文件(我正在逐渐将abc从Servlet Web应用程序转换为Spring Web应用程序)也会找到它们。
这是一次黑客攻击,而且很粗糙,但它让我现在开始