Struts2使用PreResultListener

来源:互联网 发布:数据导出系统 编辑:程序博客网 时间:2024/06/05 08:29
PreResultListener是一个监听器窗口,在Action完成控制处理之后,转到物理视图之前被回调。简单的用法如下,在Action中有一个login方法。
public String login() throws Exception {ActionInvocation invocation = ActionContext.getContext().getActionInvocation();invocation.addPreResultListener(new PreResultListener() {@Overridepublic void beforeResult(ActionInvocation arg0, String arg1) {// TODO Auto-generated method stubSystem.out.println("开始登录...");}});User u = userService.FindUser(model.getLoginName(), model.getPassword());if(u != null) {ActionContext.getContext().getSession().put("user", u);return "toindex";}else {addFieldError("login", "用户名或密码不正确!");return "loginUI";}}
0 0