天天看点

web.xml配置解释

<?xml version="1.0" encoding="UTF-8"?>
 <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
//以上为web.xml头信息,
      
//让web容器初始化的时候初始化这些配置,*号代表通配符,会在根目录下和jar包里找
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
            classpath*:applicationContext.xml
            classpath:applicationContext-quartz.xml
            classpath:applicationContext-security.xml
        </param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>      
//eclipse自带的字符编码过滤,打开web.xml,点到Tree ,选择web.xml右击新建Filte
      
//搜索 CharacterEncodingFilter

//<init-param>这个标签代表在这里过滤器的范围内,初始化的时候初始化该值,然后在这个过滤器里进行设值进去      
<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>      
//serlet 的配置 ,会拦截到url-pattern这个值的请求   
<servlet>
        <servlet-name>UploadServlet</servlet-name>
        <servlet-class>com.ecar.mp.servlet.UploadServlet</servlet-class>
        <init-param>
            <param-name>filepath</param-name>
            <param-value>upload</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>UploadServlet</servlet-name>
        <url-pattern>/upload</url-pattern>
    </servlet-mapping>      
//前端控制器;springmvc的入口,*.do所有以.do结尾的请求都会被拦截
  <servlet>
        <servlet-name>springDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map all requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>      
//配置服务启动以后初始化的页面或者请求路径
<welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>      

 此配置是整合spring,springmvc的配置,整体介绍就是让web容器初始化的时候,去初始化spring容器;

以及springmvc的入口DispatcherServlet 

继续阅读