Action的监听器——PreResultListener

这个监听器的作用是在执行完成Action后,在转发到其他Action或是显示结果之前,会调用这个类中的beforeResult()方法,以实现一些功能。通过invocation的addPreResultListener方法对监听器进行注册。

示例:

监听器类:

package com.suo.listeners;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.PreResultListener;

public class BeforeResultListener implements PreResultListener {

	@Override
	public void beforeResult(ActionInvocation invocation, String resultCode) {
		// TODO Auto-generated method stub
		System.out.println("beforeResult invoke ! "+resultCode);
	}

}
拦截器:

package com.suo.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyInterceptor implements Interceptor {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		System.out.println("init invoke !");
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		invocation.addPreResultListener(new BeforeResultListener());//增加一个监听器

		System.out.println("before MyInterceptor invoke !");
		
		String result=invocation.invoke();
		
		System.out.println("after MyInterceptor invoke !");
		
		return result;
	}

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值