struts2中的拦截器

1.定义拦截器类实现Interceptor接口


2.在struts的配置文件中:

<struts>

    <constant name="struts.ui.theme" value="simple"></constant>
    <constant name="struts.ObjectFactory" value="spring"></constant>

    <!-- 禁止对action方法的动态调用 -->
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <!-- 指定访问action的后缀类型 -->
    <constant name="struts.action.extension" value="action"></constant>
    <package name="default" namespace="/myaction" extends="struts-default">
        <!--
        在bean.xml中定义拦截器:
        写入自己定义的拦截器
        编写拦截器栈,包括系统默认的拦截器和自己定义的拦截器
        最后再想调用拦截器的action中加入拦截器栈
         -->
        <interceptors>
            <interceptor name="mi" class="com.interceptor.MyInterceptor"></interceptor>
            <interceptor-stack name="mistack">
                <interceptor-ref name="defaultStack"></interceptor-ref>
                <interceptor-ref name="mi"></interceptor-ref>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="mistack"></default-interceptor-ref>
        <global-results>
            <result name="success">/WEB-INF/page/hello.jsp</result>
        </global-results>
        <action name="hello_*" class="com.action.Hello" method="{1}">
            <interceptor-ref name="mistack"></interceptor-ref>
        </action>
    </package>
    <!-- Add packages here -->
</struts>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值