【发布时间】:2012-07-27 04:19:03
【问题描述】:
我的 web.xml 包含
<?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>
resources/index.html 通过相对路径引用存储在 resoruces 目录中的其他静态资源,如图片、js、css 等。
当我在浏览器中输入http://localhost/MyProject/ 时,它显示了 index.html 但没有得到 css 和 javascripts。
但是,如果我在浏览器中输入http://localhost/MyProject/resources/index.html,一切都会正确显示。
所以,问题是我怎样才能让 URL 中的欢迎页面作为<welcome-file> 中给出的路径,例如/resources/index.html.
如果不能在<welcome-file list> 中完成,我应该使用什么其他可配置的方法。
我倾向于不通过添加另一个 html 或通过在 Servlet 控制器中以编程方式来重定向到 /resources/index.html。
【问题讨论】:
-
你应该添加更多标签,比如'spring'、'java'...