1.说明
PreResultListener 是一个监听器接口,它可以在 Action 完成控制处理之后,系统转入实际的物理视图之间被回调。
Struts2应用可以为Action、拦截器添加 PreResultListener 监听器,添加PreResultListener 监听器通过 ActionInvocation 的 addPreResultListener() 方法完成。 一旦为 Action 添加了PreResultListener 监听器,该监听器就可以在应用转入实际物理视图之前回调该监听器的 beforeResult() 方法; 一旦为拦截器添加了 PreREsultListener 监听器,该监听器会对该拦截器所拦截的所有 Action 都起作用。
2.实例
{
public String execute()
{
ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
invocation.addPreResultListener(new PreResultListener()
{
public void beforeResult(ActionInvocation invacation, String resultCode)
{
//方法体内写我们需要处理的监听器业务逻辑
//上面的形参 resultCode 是前台发送的请求(即 Action 的逻辑名)
}
});
}
}
struts2工作原理|Struts2学习笔记PreResultListener监听器
http://m.bbyears.com/flash/45395.html
推荐访问:struts2面试题 struts2框架