zoukankan      html  css  js  c++  java
  • struts2学习之基础笔记4

     拦截器

    1.自定义拦截器类,必须继承AbstractInterceptor类(抽象类)

    重写public String intercept (ActionInvocation arg0)

    2.在Struts.xml文件中创建拦截器对象,格式: 

    <package>

    <interceptors>

    <interceptor name=拦截器名 class=拦截器类全名>

    [<param name=成员变量名 >值</~~>]

    </~~>

    </~~>

    </~~>

    3.为Action注册拦截器 格式:

    <action>

    <interceptor-ref name=拦截器名>

    [<param name=成员变量>]       作用: 成员变量赋值

    </~~>

    </~~>

    注意事项 1 当引入自定义拦截器时会导致默认拦截器失效,此时需重新引入默认拦截器栈

    格式:<inyrtceptor-ref name=defaultStack>

     2 拦截器的注册顺序即为拦截器的执行时顺序。

     3 在拦截器中参数arg0可获得 

    Action Context ac = arg.getInvocationContext();

    Map Sesstion = ac.getSession();

    拦截器栈的使用

    步骤 

    1新建拦截器栈  格式 

    <interceptors>

    <interceptor />

    <interceptor-stack name=栈名>

    < interceptor-ref name=拦截器名/>

    < /interceptor-stack>

    < /interceptor >

    2 注册拦截器栈  格式

    <action >

    < interceptor-ref name=栈名/>

    </action>

    过滤性拦截

      a.新建拦截器类 继承AbstractInterceptor类   重写doInterceptor(方法)

      b.新建或注册拦截器时

    格式:

    <interceptor interceptor-ref>

    <param name=excludeMethods>不进行拦截的Action方法名[名]

    </param>

    <param name=includeMethods>excute,abc,aa,cc,bb</param>

    </interceptor interceptor-ref>

  • 相关阅读:
    Struts初探(二)
    struts2初探(一)
    css样式表设置
    css美化Div边框的样式实例
    CSS中background样式的repeat和no-repeat
    嘘,如何激活更新的win10
    学习向上转型和向下转型的一个好例子
    atom插件安装引发的nodejs和npm安装血案
    Java--Inheritance constructor继承中的构造方法问题(二)
    Java--Inheritance constructor继承中的构造方法问题(一)
  • 原文地址:https://www.cnblogs.com/ai-xin-hong-yu/p/4234236.html
Copyright © 2011-2022 走看看