SpringMVC拦截器

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:mvc="http://www.springframework.org/schema/mvc"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6        xsi:schemaLocation="
 7        http://www.springframework.org/schema/beans
 8        http://www.springframework.org/schema/beans/spring-beans.xsd
 9        http://www.springframework.org/schema/mvc
10        http://www.springframework.org/schema/mvc/spring-mvc.xsd
11        http://www.springframework.org/schema/context
12        http://www.springframework.org/schema/context/spring-context.xsd
13 ">
14 
15     <!--控制器扫描-->
16     <context:component-scan base-package="cn.itcast.controller"></context:component-scan>
17 
18     <!--注解驱动-->
19     <mvc:annotation-driven></mvc:annotation-driven>
20 
21     <!--静态资源处理-->
22     <mvc:default-servlet-handler></mvc:default-servlet-handler>
23 
24     <!--视图解析前后缀-->
25     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
26         <property name="prefix" value="/WEB-INF/jsp/"></property>
27         <property name="suffix" value=".jsp"></property>
28     </bean>
29 
30 
31     <!--拦截器配置-->
32     <mvc:interceptors>
33 
34         <mvc:interceptor>
35             <mvc:mapping path="/**"/>
36             <bean class="cn.itcast.interceptor.Interceptor2"></bean>
37         </mvc:interceptor>
38 
39         <mvc:interceptor>
40             <mvc:mapping path="/**"/>
41             <bean class="cn.itcast.interceptor.Interceptor1"></bean>
42         </mvc:interceptor>
43 
44     </mvc:interceptors>
45 
46 </beans>
spring-mvc.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:context="http://www.springframework.org/schema/context"
 4        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5        xsi:schemaLocation="
 6        http://www.springframework.org/schema/beans
 7        http://www.springframework.org/schema/beans/spring-beans.xsd
 8        http://www.springframework.org/schema/context
 9        http://www.springframework.org/schema/context/spring-context.xsd
10 ">
11 
12     <!--组件扫描-->
13     <context:component-scan base-package="cn.itcast">
14         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:exclude-filter>
15     </context:component-scan>
16 
17 </beans>
applicationContext.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5          version="3.1">
 6 
 7     <!--spring容器监听器-->
 8     <listener>
 9         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
10     </listener>
11 
12     <context-param>
13         <param-name>contextConfigLocation</param-name>
14         <param-value>classpath:applicationContext.xml</param-value>
15     </context-param>
16 
17 
18     <!--springmvc前端控制器-->
19     <servlet>
20         <servlet-name>app</servlet-name>
21         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
22         <init-param>
23             <param-name>contextConfigLocation</param-name>
24             <param-value>classpath:spring-mvc.xml</param-value>
25         </init-param>
26         <load-on-startup>1</load-on-startup>
27     </servlet>
28 
29     <servlet-mapping>
30         <servlet-name>app</servlet-name>
31         <url-pattern>/</url-pattern>
32     </servlet-mapping>
33 
34 
35     <!--编码过滤-->
36     <filter>
37         <filter-name>CharacterEncodingFilter</filter-name>
38         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
39         <init-param>
40             <param-name>encoding</param-name>
41             <param-value>UTF-8</param-value>
42         </init-param>
43     </filter>
44     <filter-mapping>
45         <filter-name>CharacterEncodingFilter</filter-name>
46         <url-pattern>/*</url-pattern>
47     </filter-mapping>
48 
49 </web-app>
web.xml

 

posted @ 2019-06-11 16:20  没有理由不会呀  阅读(205)  评论(0编辑  收藏  举报