zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    Django-url反向解析和命名空间
    django-分页paginator
    python-命令模式
    python-访问者模式
    python-责任链模式
    python-备忘录模式
    最长无重复字串
    计算机网络常见面试题
    C++对象模型
    原码反码补码(转)
  • 原文地址:https://www.cnblogs.com/goingforward/p/5729887.html
Copyright © 2011-2022 走看看