• PreResultListener使用


    PreResultListener是一个监听器接口,可以在Action处理完之后,系统转入实际视图前被回调。
    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;
        }
  • 相关阅读:
    Reporting Services 配置工具
    管道符、重定向和环境变量
    靶机DC-2 rbash绕过+git提权
    单表查询
    数据库和表的基本操作(二)
    数据库和表的基本操作(一)
    MySQL的约束
    bugku-misc 9-16
    Linux基础命令
    时间-i春秋
  • 原文地址:https://www.cnblogs.com/goingforward/p/5729887.html
Copyright © 2020-2023  润新知