web.xml的基础配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_4_0.xsd"
         version="4.0">

    
    <!-- 前端控制器 -->
    <servlet>
        <servlet-name>springMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
            <!--<param-value>/WEB-INF/web.xml</param-value>--><!-- 现在有上下两种结构,还不明白都什么意思 -->
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMVC</servlet-name>
        <!-- 伪静态,也是不解 -->
        <!--<url-pattern>*.html</url-pattern>-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    
    <!-- spring监听器(直接在启动的时候加载的applicationContext的xml文件{自己加的解释}) -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:/applicationContext.xml
<!--            classpath*:/applicationContext-dao.xml
            classpath*:/applicationContext-shiro.xml-->
        </param-value>
    </context-param>

    
    <!-- post乱码过滤器 -->
    <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>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <!-- * 代表截获所有的请求  或拦截指定请求/test.do  /xxx.do -->
        <url-pattern>/*</url-pattern>
        <!--      <dispatcher>REQUEST</dispatcher>
                <dispatcher>FORWARD</dispatcher> -->
    </filter-mapping>

    
    <!-- Session容器失效时间 -->
    <session-config>
        <session-timeout>20</session-timeout>
    </session-config>


    <!-- 监听器, -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!-- 访问的顺序 -->
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

</web-app>

猜你喜欢

转载自blog.csdn.net/potatoandpotato/article/details/80302798
今日推荐