struts拦截器includeMethods或excludeMethods没起作用

自定义拦截器public class EstimateInterceptor extends AbstractInterceptor 如果继承的是AbstractInterceptor 不会拦截xml中设置的includeMethods或excludeMethods

struts2MethodFilterInterceptor类,该类是AbstractInerceptor的子类,可以实现对Action方法的拦截.实现MethodFilterInterceptor才能使用方法拦截
    MethodFilterInterceptor中有两个方法
   setExcludeMethods:排除需要过滤的方法
    setIncludeMethods:设置需要过滤的方法
    如果一个方法同时在excludeMethods和includeMethods中出现,则会被拦截

Struts2中提供了一个MethodFilterInterceptor的类,开发者自定义的拦截器只需要继承该类就可以使用这个方法过滤的功能,来拦截Action中特定的方法!

MethodFilterInterceptor类是AbstractInterceptor拦截器的子类,实现了Interceptor和Serializable接口

MethodFilerInterceptor实现方法过滤中用到的两个参数

execludeMethods:该参数指定拦截器拒绝拦截的方法列表,多个方法用“,”隔开,指定了这个参数,拦截器不会拦截指定列表中的方法

includeMethods:该参数指定拦截器需要拦截的方法列表,如果指定了参数,则指定的Action在执行前会被拦截

主要方法:

①protected abstract String doIntercept(ActionInvocation invocation) throws Exception; 必须重写此方法,实现拦截。

②String interceptor(ActionInvocation invocation):继承自AbstractInterceptor类,方法不需要强制重写

③void setExcludeMethods(String excludeMethods):设置拦截器黑名单,参数为Action一方法名。拦截器不拦截该方法

④void setIncludeMethods(String includeMethods):设置拦截器白名单,参数为Action一方法名。拦截器会拦截该方法

⑤Set getExcludeMethodsSet():获得拦截器的黑名单

⑥Set getIncludeMethodsSet():获得拦截器的白名单


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值