springmvc(拦截器)

   1. <!--定义拦截器 -->
        <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()




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值