開發文檔 web.xml基本配置

  • 2019 年 11 月 1 日
  • 筆記

版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。

本文鏈接:https://blog.csdn.net/weixin_44580977/article/details/98133532

<!DOCTYPE web-app PUBLIC   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"   "http://java.sun.com/dtd/web-app_2_3.dtd" >    <web-app>    <display-name>Archetype Created Web Application</display-name>      <!--配置Spring的監聽器,默認只載入WEB-INF目錄下的applicationContext.xml配置文件-->    <listener>      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>    <!--設置配置文件的路徑-->    <context-param>      <param-name>contextConfigLocation</param-name>      <param-value>classpath:applicationContext.xml</param-value>    </context-param>    <context-param>      <param-name/>      <param-value/>    </context-param>      <!--配置前端控制器-->    <servlet>      <servlet-name>dispatcherServlet</servlet-name>      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      <!--載入springmvc.xml配置文件-->      <init-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:springmvc.xml</param-value>      </init-param>      <!--啟動伺服器,創建該servlet-->      <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>      <servlet-name>dispatcherServlet</servlet-name>      <url-pattern>/</url-pattern>    </servlet-mapping>      <!--解決中文亂碼的過濾器-->    <filter>      <filter-name>characterEncodingFilter</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>    </filter>    <filter-mapping>      <filter-name>characterEncodingFilter</filter-name>      <url-pattern>/*</url-pattern>    </filter-mapping>    </web-app>