您的位置:首页 > 编程语言 > Java开发

SpringMVC的web.xml的配置。

2016-06-16 15:48 465 查看
大致配置如下:

<?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:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name></display-name>

  <!-- spring框架必须定义ContextLoaderListener,在启动Web容器时,自动装配Spring applicationContext.xml的配置信息 -->

  <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

  

  <context-param>

 <!-- 指定Spring上下文配置文件 -->

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath*:applicationContext.xml</param-value>

  </context-param>  

  <servlet>

    <servlet-name>spring</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>

<!-- 指定SpringMVC配置文件 -->

      <param-name>contextConfigLocation</param-name>

      <param-value>/WEB-INF/spring-mvc.xml</param-value>

    </init-param>

  </servlet>

  <servlet-mapping>

    <servlet-name>spring</servlet-name>

    <!-- 指定请求的后缀,可以随意写,这里用.html作为请求后缀 -->

    <url-pattern>*.html</url-pattern>

  </servlet-mapping>

  

  <welcome-file-list>

  <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

  

</web-app>

或者:

<?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:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name></display-name>

  <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

  <listener>

    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

  </listener>

  <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath*:applicationContext.xml</param-value>

  </context-param>

  <context-param>

    <param-name>spring.profiles.active</param-name>

    <param-value>production</param-value>

  </context-param>

  <servlet>

    <servlet-name>spring</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>

      <param-name>contextConfigLocation</param-name>

      <param-value>/WEB-INF/spring-mvc.xml</param-value>

    </init-param>

  </servlet>

  <servlet-mapping>

    <servlet-name>spring</servlet-name>

    <url-pattern>*.html</url-pattern>

  </servlet-mapping>

<!-- 编码格式为UTF-8 -->

  <filter>

    <filter-name>encodingFilter</filter-name>

    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

    <init-param>

      <param-name>encoding</param-name>

      <param-value>UTF-8</param-value>

    </init-param>

    <init-param>

      <param-name>forceEncoding</param-name>

      <param-value>false</param-value>

    </init-param>

  </filter>

  <filter-mapping>

    <filter-name>encodingFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  

  <session-config>

    <session-timeout>1440</session-timeout>

  </session-config>

  <welcome-file-list>

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

  </welcome-file-list>

  <error-page>

    <error-code>403</error-code>

    <location>/WEB-INF/page/error/403.jsp</location>

  </error-page>

  <error-page>

    <error-code>404</error-code>

    <location>/WEB-INF/page/error/404.jsp</location>

  </error-page>

  <error-page>

    <error-code>400</error-code>

    <location>/WEB-INF/page/error/404.jsp</location>

  </error-page>

  <error-page>

    <error-code>500</error-code>

    <location>/WEB-INF/page/error/500.jsp</location>

  </error-page>

</web-app>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: