• 自定义拦截器


    首先自定义拦截器需要实现Interceptor接口

    package control.center;

    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.Interceptor;

    public class PersonAction implements Interceptor {

     @Override
     public void destroy() {

     }

     @Override
     public void init() {

     }

     @Override
     //当拦截到Action的时候执行该方法
     public String intercept(ActionInvocation arg0) throws Exception {

      Object user=ActionContext.getContext().getSession().get("user");
      if(user!=null)
      {
       //调用该用法就执行被拦截到的方法
       arg0.invoke(); 
      }
      ActionContext.getContext().put("message","你没有权限执行该操作"); 
      return "message";
     }

    }

    然后再struts2配置文件中声明和使用拦截器:

    <struts>
        <package name="employee" namespace="/control/center" extends="struts-default">
           <!--
                                   配置中声明自定义拦截器
                                  自定义拦截器后,默认的拦截器不能在使用,所以要使用拦截器栈
           -->
           <interceptors>
              <!--<interceptor name="Permission" class="control.center.HelloWordAction"/> -->
              <interceptor-stack name="permissionStack">
                 <!-- 引入系统默认拦截器栈 -->
                 <interceptor-ref name="defaultStack"/>
                 <!-- 引入自定义拦截器 -->
                 <interceptor-ref name="permission"/>
              </interceptor-stack>
           </interceptors>
          
            <action name="list_*" class="control.center.HelloWordAction" method="{1}">
                <!--在Action中应用拦截器-->            
                <interceptor-ref name="permission"/>
                <result type="success">/WEB-INF/message.jsp</result>
            </action>
        </package>
    </struts>

  • 相关阅读:
    Percona: How to Restore MySQL Logical Backup at Maximum Speed
    MySQL之UNDO及MVCC、崩溃恢复
    MySQL checkpoint深入分析
    关于MySQL latch争用深入分析与判断
    InnoDB关键特性之刷新邻接页-异步IO
    InnoDB关键特性之自适应hash索引
    MySQL后台线程的清理工作
    MySQL IO线程及相关参数调优
    MySQL存储写入性能严重抖动分析
    MySQL的SQL预处理(Prepared)
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1965737.html
Copyright © 2020-2023  润新知