java拦截器执行顺序

拦截器的执行顺序:

 

一个拦截器:textOne.java

public class textOne extends AbstractInterceptor {


 public String intercept(ActionInvocation invocation) throws Exception {
  System.out.println("拦截器11111前");
  String result = invocation.invoke(); 
  System.out.println("拦截器11111后");
  return result;


 }
}

 

另一个拦截器:textTwo.java

public class textTwo extends AbstractInterceptor{


 public String intercept(ActionInvocation invocation) throws Exception {
  System.out.println("拦截器22222前");
  String result = invocation.invoke(); 
  System.out.println("拦截器22222后");
  return result;
 }
}

 

随便一个页面:

 /**
  * 转向登录页面
  */
 public String goLogin() throws Exception { 

System.out.println("你好!《》《》《》");
  roleList = roleService.getRoles();
  String forward = AppConstants.RETURN_TYPE_FREEMARKER; 
  return forward;
 }

 

在struts.xml中配置好拦截器

<interceptors>
   <interceptor name="userSession" class="com.yuanit.app.interceptor.UserSessionInterceptor"/>
   <interceptor name="logInterceptor" class="com.yuanit.app.interceptor.LogInterceptor"/>
   <interceptor name="textOne" class="com.yuanit.app.interceptor.textOne"/>
   <interceptor name="textTwo" class="com.yuanit.app.interceptor.textTwo"/>
   <interceptor-stack name="interceptorStack">
     <interceptor-ref name="logInterceptor" />
     <interceptor-ref name="defaultStack" /> 
        </interceptor-stack>   
</interceptors>

 

<action name="*_*" class="com.yuanit.app.action.{1}Action" method="{2}">
   <result name="json" type="json">
      <param name="includeProperties">
           resultInfo/.success,resultInfo/.message
      </param>
   </result>
   <result name="freemarker" type="freemarker">template/app/{1}/{2}.ftl</result>
   <interceptor-ref name="textOne" />
   <interceptor-ref name="textTwo" />

</action>

 

这样配置后,运行程序结果是:

拦截器11111前
拦截器22222前
你好!《》《》《》
拦截器22222后
拦截器11111后

 

拦截器的运行顺序!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值