拦截器未在Struts中被调用 [英] Interceptor not getting called in Struts
本文介绍了拦截器未在Struts中被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在操作之前或之后没有调用我的拦截器(验证).任何想法如何使它起作用?
My interceptor (validation) is not getting called before or after the action. Any ideas how to get it work ?
注意:每次调用默认拦截器.
Note : Everytime the default interceptor is being called.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default,json-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>
<interceptors>
<interceptor name="validation" class="ValidatorBaseAction"/>
<interceptor-stack name="default">
<interceptor-ref name="logger"/>
</interceptor-stack>
<interceptor-stack name="validationStack">
<interceptor-ref name="validation"/>
<interceptor-ref name="default"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="default" />
<action
name="viewRequest"
class="ViewAction"
method="execute">
<interceptor-ref name="validationStack" />
<result name="input" type="redirectAction">explore</result>
<result name="success" type="redirect">/showRequest.do?${explorerParameters}</result>
</action>
</package>
</struts>
推荐答案
主要问题:
-
动作和拦截器的
-
class
都必须指定 FQCN ,而不仅是名称.然后将其更改为:Main problem:
class
both for Actions and Interceptors must specify the FQCN, not only the name. Then change it to something like:<interceptor name="validation" class="com.foo.bar.ValidatorBaseAction"/>
,然后将操作更改为
<action name="viewRequest" class="com.foo.bar.ViewAction" method="execute">
- 如果它不是
Interceptor
,请不要将其命名为ValidatorBaseAction
,而应将其命名为ValidatorBaseInterceptor
.并确保其中没有任何动作 ; - 不要仅使用一个拦截器使用拦截器堆栈,我敢肯定,在99%的情况下,它是没有用的.如果不确定,只需使用defaultStack,然后将拦截器添加到其中即可.
- Don't call it
ValidatorBaseAction
if it is anInterceptor
, call itValidatorBaseInterceptor
. And ensure there is nothing of an Action inside it; - Don't use an Interceptor Stack with only one Interceptor, I'm pretty sure it would be useless in 99% of the cases. If you are not sure, just use the defaultStack, adding your interceptor to it.
查看全文