简体   繁体   English

在Struts2中从堆栈中删除拦截器

[英]Delete interceptor from stack in Struts2

In struts.xml , I have included tokenSession interceptor to my interceptor-stack to validate token for each request. struts.xml ,我将tokenSession拦截器包含在我的拦截器堆栈中,以验证每个请求的令牌。 Unfortunately, the same isn't working well for AJAX requests. 不幸的是,对于AJAX请求,这种方法效果不佳。 I got invalid.token response when it executes actionInvocation.invoke() . 执行actionInvocation.invoke()时,我得到了invalid.token响应。

Hence, I would like to stop executing tokenSession interceptor for AJAX requests (alone). 因此,我想停止为AJAX请求执行tokenSession拦截器(单独)。 I have a custom interceptor (logging) which get invoked prior to tokenSession interceptor. 我有一个自定义拦截器(日志记录),它在tokenSession拦截器之前被调用。 Is it possible to delete tokenSession interceptor from stack in logging interceptor based on request type (if it is an AJAX request)? 是否可以根据请求类型(如果是AJAX请求)从日志拦截器中的堆栈中删除tokenSession拦截器?

Token interceptor extends MethodFilterInterceptor that means that you can exclude execution of interceptor bases on method names. 令牌拦截器扩展了MethodFilterInterceptor ,这意味着您可以在方法名称上排除拦截器基础的执行。

In your interceptor stack configure it like that: 在你的拦截器堆栈中配置它:

<interceptor-ref name="token">
   <param name="excludeMethods">your_ajax_methods_comma_separated</param>
</interceptor-ref>

Another solution is to use different interceptor stack for you AJAX actions. 另一种解决方案是为您的AJAX操作使用不同的拦截器堆栈。

为Action使用不同的拦截器堆栈,或者为不同的包使用不同的拦截器堆栈,并将正确包中的所有Actions组合在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM