1. <!--定义拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>(全部拦截)
<!-- 不拦截页面-->
<mvc:exclude-mapping path="index.jsp"/>
<bean class="demo.controller.Interceptor"></bean>
</mvc:interceptor>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>(全部拦截)
<!-- 不拦截页面-->
<mvc:exclude-mapping path="index.jsp"/>
<bean class="demo.controller.Interceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
2.实现HandlerInterceptor接口
3. 第一种方式是要定义的Interceptor类要实现了Spring的HandlerInterceptor 接口
第二种方式是继承实现了HandlerInterceptor接口的类,比如Spring已经提供的实现了HandlerInterceptor接口的抽象类HandlerInterceptorAdapter
HandlerInterceptor 接口中定义了三个方法,我们就是通过这三个方法来对用户的请求进行拦截处理的。
preHandle():返回true通过否则失败
postHandle():
afterCompletion()