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>
             
     
     
  • 相关阅读:
    bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)
    bzoj 2186 [Sdoi2008]沙拉公主的困惑(欧拉函数,逆元)
    bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
    c3p0 连接池配置
    Hibernate连接池断开自动重连
    Oracle ASM注意事项
    JAVA如何获得数据库的字段及字段类型
    在引入的css或者js文件后面加参数的作用
    JAVA注解
    Linux软连接和硬链接
  • 原文地址:https://www.cnblogs.com/wq-code/p/8360993.html
Copyright © 2011-2022 走看看