拦截器

Struts2的拦截器其实是AOP思想的一种实现,可以实现Interceptor接口也同时可以继承abStractInterceptor类,该类对init和distory进行了空实现

public String intercept(ActionInvocation invocation) throws Exception ;主要显示intercept方法

此方法将action和result之间分为了四层:即拦截器、action、preResultListener(到达action后在返回结果之前进行的操作)、和Result


invocation.invoke之前为拦截器到达action之前的操作,位于拦截器栈底,即将执行action,当执行了invoke方法后已经执行了acion等待result返回 找到具体视图,从栈底依次出栈


具体配置

<interceptors>
   <interceptor name="testInterceptor" class="com.test.struts2.testInterceptor"></interceptor>
   <interceptor-stack name="testInterceptorStack">
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="testInterceptor" />
   </interceptor-stack>
  </interceptors>
  <default-interceptor-ref name="testInterceptorStack"></default-interceptor-ref>

invocation提供了getProxy().getMethod()可以返回代理拦截的方法,同时也可以继承MethodFilterInterceptor 已经实现好得方法拦截器

需要配置如下

<interceptors> <! - -在这里定义拦截器- ->

<interceptor name=“around” class=“AroundInterceptor”/>

</interceptors>             
        < action name =“test” class =“cn.com.AroundAction” >              
           < result > /Timer.jsp </ result >

< interceptor-ref name =“around”>

<param name=“includeMethods”>select,update</param>

<param name=“excludeMethods”>delete,insert</param>

</interceptor-ref>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值