我的web.xml包含诸如图像,JS,CSS等存储在resoruces目录由相对路径如何在web.xml中正确映射Spring应用程序的内容?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
resources/index.html
</welcome-file>
</welcome-file-list>
</web-app>
的对其他静态资源资源/ index.html中引用。
当我在浏览器中放入http://localhost/MyProject/
时,它显示index.html,但没有得到css和javascripts。
但是,如果我在浏览器中放置了,则所有内容都正确显示。
所以,问题是我该如何让url中的欢迎页面成为<welcome-file>
中给出的路径,例如: /resources/index.html。
如果无法在<welcome-file list>
中完成,还应该使用其他可配置的方法。
我倾向于不通过添加另一个html或通过在Servlet控制器中以编程方式执行重定向到/resources/index.html。
你应该添加更多的标签,如'spring','java'... – 2012-07-27 04:50:35