文章标题

来源:互联网 发布:大华网络监控远程设置 编辑:程序博客网 时间:2024/06/05 02:39
<mvc:interceptors>      <!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->      <bean class="com.host.app.web.interceptor.AllInterceptor"/>      <mvc:interceptor>          <mvc:mapping path="/test/number.do"/>          <!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->          <bean class="com.host.app.web.interceptor.LoginInterceptor"/>      </mvc:interceptor>  </mvc:interceptors>  

由上面的示例可以看出可以利用mvc:interceptors标签声明一系列的拦截器,然后它们就可以形成一个拦截器链,拦截器的执行顺序是按声明的先后顺序执行的,先声明的拦截器中的preHandle方法会先执行,然而它的postHandle方法和afterCompletion方法却会后执行。
在mvc:interceptors标签下声明interceptor主要有两种方式:
(1)直接定义一个Interceptor实现类的bean对象。使用这种方式声明的Interceptor拦截器将会对所有的请求进行拦截。
(2)使用mvc:interceptor标签进行声明。使用这种方式进行声明的Interceptor可以通过mvc:mapping子标签来定义需要进行拦截的请求路径。
经过上述两步之后,定义的拦截器就会发生作用对特定的请求进行拦截了。

原创粉丝点击