Action的监听器——PreResultListener
2011-11-20 23:17
302 查看
这个监听器的作用是在执行完成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; } }
相关文章推荐
- struts2 拦截器和actioninvocation、PreResultListener
- Struts2中使用PreResultListener来查看action与jsp执行
- Struts2中PreResultListener的简单示例
- JAVA:事件监听器之Button类中的addActionListener(ActionListener l)方法
- Struts2拦截器-PreResultListener
- Struts2拦截器(Interceptor) PreResultListener
- 《研磨struts2》第五章 Result 之 5.6 PreResultListener
- PreResultListener
- struts2之PreResultListener(转)
- 实现监听器类 ButtonActionListener
- Struts 2使用PreResultListener
- Struts 2 读书笔记-----使用PreResultListener
- Struts 2 读书笔记-----使用PreResultListener
- PreResultListener
- Struts2拦截器-PreResultListener
- 3.7.10: 配置处理结果---使用PreResultListener
- Struts2拦截器-PreResultListener
- Struts2使用PreResultListener
- [Java] Mouse/Window/ActionListener 多个事件监听器
- [Java] Mouse/Window/ActionListener 多个事件监听器