拦截器动作类排除

有些动作类不需要设置拦截器,那么就要排除使用这个拦截器,如果某一个拦截器需要被排除使用,那么这个拦截器创建的时候,就不能继承AbstractInterceptor而是继承:MethodFilterInterceptor


代码:

package com.rl.intereptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class Myinterceptor1 extends MethodFilterInterceptor {


	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		
		System.out.println("做一些前置工作111");
		
		//让拦截器向下走,并且返回结果代码:成功或者失败
		String invoke = invocation.invoke();
		
		System.out.println("做一些后置工作111");
		
		return invoke;
	}

}


同样,,需要在struts.xml中配置拦截器

<package name="my-interceptorSrack" extends="struts-default" abstract="true">
		<interceptors>
			<!-- 配置自己的拦截器 -->
			<interceptor name="myInterceptor" class="com.rl.intereptor.Myinterceptor"></interceptor>
			<!-- 这个是delete方法不使用的拦截器的配置 -->
			<interceptor name="myInterceptor1" class="com.rl.intereptor.Myinterceptor1"></interceptor>
			
			<!-- 配置拦截器栈 -->
			<interceptor-stack name="rlStack">

				<!-- 拦截器栈中要引用已经配置好的拦截器或者拦截器栈 -->
				<interceptor-ref name="myInterceptor"></interceptor-ref>
				<!-- 这个拦截器delete方法不使用 -->
				<interceptor-ref name="myInterceptor1"></interceptor-ref>
				<interceptor-ref name="defaultStack"></interceptor-ref>

			</interceptor-stack>
		</interceptors>
		
		<!-- 把自己配置的rlStack拦截器栈设置成默认的拦截器,只要继承了my-interceptorSrack,就默认执行rlStack中的所有拦截器 -->
		<default-interceptor-ref name="rlStack"></default-interceptor-ref>
	</package>

如果在delete方法中不使用这个拦截器,首先,需要在action中引入默认的拦截器栈,

然后增加属性

<!--

                    指定要排除的拦截器

                    name:要排除的拦截器的名字.exludeMethods

                    元素:要排除的方法

                 -->

<action name="delete" class="com.rl.action.PersonAction" method="delete">
			<!-- 首先引入默认的拦截器栈 -->
			<interceptor-ref name="rlStack">
				<!-- 排除的拦截器方法名.excludeMethods 
					括号中最好写上方法名,防止动态的方法
				 -->
				<param name="myInterceptor1.excludeMethods">delete</param>
			</interceptor-ref>
			<result name="success">/success.jsp</result>
			<result name="input">/form.jsp</result>
		</action>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值