zoukankan      html  css  js  c++  java
  • java学习笔记 (5) —— Struts2 监听器配置

    1、创建MyListener.java 实现 PreResultLisener 接口

    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.PreResultListener;
    
    public class MyListener implements PreResultListener {
    
        public void beforeResult(ActionInvocation invocation, String resultCode) {
            System.out.println("result : "+resultCode);
        }
    
    }

    2、在拦截器中引入监听器

    package com.test.interceptor;
    
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
    import com.test.Listener.MyListener;
    
    public class MyInterceptorMet extends MethodFilterInterceptor {
    
        private static final long serialVersionUID = 8722841247439200544L;
    
        @Override
        protected String doIntercept(ActionInvocation invocation) throws Exception {
            invocation.addPreResultListener(new MyListener());
            System.out.println("my interceptor method");
         // 执行 Action String result
    = invocation.invoke(); return result; } }

    3、执行顺序

    validateDM is invoked —— 先进检验方法
    my interceptor method —— 实例化监听器,并没有输出内容
    DesignMethod is invoked —— 依然会执行Action方法
    result : success —— 如果提交成功返回 success ,否则 返回input

  • 相关阅读:
    bootstrap 辅助类
    bootstrap 表单类
    bootstrap 图片类 和 按钮类 部分
    angularJs学习笔记-入门
    react-conponent-todo
    react-conponent-secondesElapsed
    react-conponent-hellocynthia
    react学习笔记1
    1970年// iPhone “变砖”后可继续正常使用的解决方案
    23种设计模式
  • 原文地址:https://www.cnblogs.com/cklovefan/p/5252952.html
Copyright © 2011-2022 走看看