liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
    <!-- web.xml中加载顺序 context-param -> listener -> filter -> servlet  -->
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>webapp.root</param-value>
    </context-param>
   <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>WEB-INF/config/log4j.properties</param-value>
    </context-param>
    <!-- 设置Spring容器加载所有的配置文件的路径 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/config/spring-*.xml</param-value>
    </context-param>
 
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    
    <!-- 加载Spring容器配置 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>  
        <listener-class>
            org.springframework.web.context.request.RequestContextListener  
        </listener-class>
    </listener> 
 
    <!-- 配置SpringMVC核心控制器 -->
    <servlet>
        <servlet-name>springMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 配置初始配置化文件-->  
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/config/servlet-mvc.xml</param-value>
        </init-param>
        <!-- 启动加载一次 -->  
        <load-on-startup>0</load-on-startup>
    </servlet>
 
    <!--为DispatcherServlet建立映射 -->
    <servlet-mapping>
        <servlet-name>springMVC</servlet-name>
        <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
 
    <!-- 防止Spring内存溢出监听器 -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
 
    <!-- 解决工程编码过滤器 -->
    <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>
        <filter-name>menuFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
     </filter>
 
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter-mapping>
        <filter-name>menuFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
 
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
    
    <error-page>  
        <exception-type>java.lang.Throwable</exception-type>  
        <location>/error</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/error?httpCode=500</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/error?httpCode=404</location>
    </error-page>
    <error-page>
        <error-code>405</error-code>
        <location>/error?httpCode=405</location>
    </error-page>
    
    <jsp-config>
        <taglib>
            <taglib-uri>frame</taglib-uri>
            <taglib-location>/WEB-INF/tld/frame.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>