1.主要功能&触发时间
该监听器主要在action的execute方法执行完以后,result.execute()方法执行前调用。
接口如下
在DefaultActionInvocation对应的调用如下
2.注册方法
通过调用 invocation.addPreResultListener具体代码如下(摘自struts2 docs)
该监听器主要在action的execute方法执行完以后,result.execute()方法执行前调用。
接口如下
public interface PreResultListener {
void beforeResult(ActionInvocation invocation, String resultCode);
}
在DefaultActionInvocation对应的调用如下
//判断是否还有拦截器未执行,如果还有则继续执行拦截器链
//这里通过把DefaultActionInvocation对象本身往后续拦截器中传递来实现interceptors这个interceptor的迭代。
if (interceptors.hasNext()) {
final InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();
UtilTimerStack.profile("interceptor: "+interceptor.getName(),
new UtilTimerStack.ProfilingBlock<String>() {
public String doProfiling() throws Exception {
resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
return null;
}
});
} else {
//所有拦截器执行完成调用action的执行方法。
resultCode = invokeActionOnly();
}
// this is needed because the result will be executed, then control will return to the Interceptor, which will
// return above and flow through again
//调用preResultListeners的内容
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();
String _profileKey="preResultListener: ";
try {
UtilTimerStack.push(_profileKey);
listener.beforeResult(this, resultCode);
}
finally {
UtilTimerStack.pop(_profileKey);
}
}
}
// now execute the result, if we're supposed to
//调用result.execute方法.
if (proxy.getExecuteResult()) {
executeResult();
}
executed = true;
}
2.注册方法
通过调用 invocation.addPreResultListener具体代码如下(摘自struts2 docs)
public class MyAction extends ActionSupport {
...
public String execute() throws Exception {
ActionInvocation invocation = ActionContext.getActionInvocation();
invocation.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation invocation,
String resultCode) {
// perform operation necessary before Result execution
}
});
}
...
}
发表评论
- 浏览: 7964 次
- 性别:

- 来自: 福建福州

- 详细资料
搜索本博客
最新评论
-
struts2实践- 结合jquery ...
客户端和服务端配合验证的方案有吗?
-- by hotdog -
struts2实践- 结合jquery ...
只用js验证很不保险,服务端验证不可少
-- by kjj -
struts2实践- 结合jquery ...
jquery 比较耗资源~
-- by happy002 -
struts2实践-页面分页的 ...
能发一个吗 谢谢 dawnco@163.com
-- by adapt -
struts2实践- 结合jquery ...
long_jianxiu 写道不晓得有没有完整的代码,我现在弄的一头雾水的,不知 ...
-- by luckaway






评论排行榜