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>
             
     
     
  • 相关阅读:
    Integer中计算int位数的方法
    Spark学习---常见的RDD转和行动操作
    Spark学习---RDD编程
    《教父》中的经典台词以及英文原版
    关于MATSIM中,如何关闭自动加载dtd的问题
    源发行版8需要目标发行版1.8
    关于Mysql中GROUP_CONCAT函数返回值长度的坑
    【转】通过xml处理sql语句时对小于号与大于号的处理转换
    XmlDocument根据节点的属性值获取节点
    【转】使用SevenZipSharp压缩、解压文件
  • 原文地址:https://www.cnblogs.com/wq-code/p/8360993.html
Copyright © 2011-2022 走看看