zoukankan      html  css  js  c++  java
  • 拦截器

    • 获取作用域对象
      String name="";
      HttpServletRequest request = ServletActionContext.getRequest();
      request.setAttribute("info", name);
      HttpServletResponse response = ServletActionContext.getResponse();   
      HttpSession session = request.getSession();
      ServletContext application = ServletActionContext.getServletContext();
    • 拦截器
      • 编写拦截器
        • 声明一个类,让这个类继承(implements) Interceptor接口;
      • 声明拦截器
        <interceptors>
               <interceptor name="testInt_register" class="action.TestInt"></interceptor> <!-- 声明拦截器 -->
        </interceptors>
      • 映射拦截器
        <interceptor-ref name="testInt_register"></interceptor-ref> <!-- 映射拦截器 -->
      • 多个拦截器
        • 多个拦截器映射的顺序就是调用的顺序;
          <struts>
                <package name="struts02" extends="struts-default">
                     <interceptors>
                           <interceptor name="testInt_register" class="action.TestInt"></interceptor> <!-- 声明拦截器 -->
                           <interceptor name="testInt_reg" class="action.TestInt01"></interceptor>
                     </interceptors>
                     <action name="register" class="action.RegisterAction" method="register">
                     
                           <interceptor-ref name="testInt_reg"></interceptor-ref>
                           <interceptor-ref name="testInt_register"></interceptor-ref> <!-- 映射拦截器 -->
                           
                           <result>registerSuccess.jsp</result>
                     </action>
                </package>
          </struts>
           配置自定义拦截器后,默认拦截器全部失效,需要在action后加入:
          <interceptor-ref name="basicStack"></interceptor-ref>
      • 拦截器的堆栈
        <interceptors>
               <interceptor name="testInt_register" class="action.TestInt"></interceptor> <!-- 声明拦截器 -->
               <interceptor name="testInt_reg" class="action.TestInt01"></interceptor>
               <!-- 拦截器堆栈 -->
               <interceptor-stack name="mystack">
                      <interceptor-ref name="testInt_reg"></interceptor-ref> <!-- 映射拦截器 -->
                      <interceptor-ref name="testInt_register"></interceptor-ref>
                       <interceptor-ref name="basicStack"></interceptor-ref>
               </interceptor-stack>  
        </interceptors>
             
     
     
  • 相关阅读:
    Java自学-数组 创建数组
    Java自学-控制流程 结束外部循环
    Java自学-控制流程 break
    Java自学-控制流程 for
    Java自学-控制流程 continue
    Java自学-控制流程 switch
    Java自学-控制流程 If
    计算机组成原理之流水线处理器
    计算机组成原理之算术逻辑单元
    计算机组成原理之指令系统
  • 原文地址:https://www.cnblogs.com/wq-code/p/8360993.html
Copyright © 2011-2022 走看看