我怎样才能用扩展名.html的文件制作欢迎页面

  • 本文关键字:文件 html 扩展名 spring
  • 更新时间 :
  • 英文 :


你好,我是春天的新手, 我正在尝试创建一个名为索引的欢迎文件.html 我将索引.html文件放在网络应用程序文件夹下。我的网络 xml 文件是

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring4MVCHelloWorldDemo Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>

我的弹簧.xml文件是

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.websystique.springmvc" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

当我将 index.html 更改为 index.jsp 并创建一个 index.jsp 文件时,它工作正常。我的问题是我不能制作带有html扩展名的欢迎页面吗?如果可以,我的错误是什么?谢谢

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

您已将InternalResourceViewResolver配置为搜索带有.jsp后缀的文件。在这种情况下,春天不会匹配index.html

如果需要匹配/WEB-INF/views/{viewName}.html下的文件,可以将suffix值替换为.html

最新更新