PreResultListener使用
2016-08-02 16:49
435 查看
PreResultListener是一个监听器接口,可以在Action处理完之后,系统转入实际视图前被回调。
Struts2应用可以给Action、拦截器添加PreResultListener监听器,添加PreResultListener可以通过ActionInvocation的addPreResultListener()方法完成:
Struts2应用可以给Action、拦截器添加PreResultListener监听器,添加PreResultListener可以通过ActionInvocation的addPreResultListener()方法完成:
// Action默认包含的控制逻辑 public String execute() throws Exception { ActionInvocation invocation = ActionContext .getContext().getActionInvocation(); invocation.addPreResultListener(new PreResultListener() { public void beforeResult(ActionInvocation invocation, String resultCode) { System.out.println("返回的逻辑视图名字为:" + resultCode); // 在返回Result之前加入一个额外的数据。 invocation.getInvocationContext().put("extra" , new java.util.Date() + "由" + resultCode + "逻辑视图名转入"); // 也可加入日志等 } }); if (getUsername().equals("crazyit.org") && getPassword().equals("leegang") ) { ActionContext.getContext().getSession() .put("user" , getUsername()); addActionMessage("欢迎," + getUsername() + ",您已经登录成功!"); return SUCCESS; } return ERROR; }
相关文章推荐
- 3.7.10: 配置处理结果---使用PreResultListener
- Struts 2 读书笔记-----使用PreResultListener
- Struts 2 读书笔记-----使用PreResultListener
- Struts2.x 之 使用PreResultListener
- Struts2中使用PreResultListener来查看action与jsp执行
- Struts 2 读书笔记-----使用PreResultListener
- Struts 2 读书笔记-----使用PreResultListener
- Struts2使用PreResultListener
- Struts 2使用PreResultListener
- Struts2-学习笔记系列(7)-PreResultListener
- Struts2拦截器-PreResultListener
- Struts2拦截器-PreResultListener
- Struts2拦截器-PreResultListener
- PreResultListener
- struts2 拦截器和actioninvocation、PreResultListener
- PreResultListener
- 《研磨struts2》第五章 Result 之 5.6 PreResultListener
- Struts2中PreResultListener的简单示例
- PreResultListener
- Struts2-监听返回结果(PreResultListener)