Struts 2:仅从defaultStack拦截器中将方法从验证中排除 [英] Struts 2: excluding method from validation from just the defaultStack interceptor
问题描述
我希望能够对Struts 2中的一项操作禁用表单验证,但让其余的拦截器堆栈仍然能够运行.
I want to be able to disable form validation for one action in Struts 2, but have the rest of the interceptor stack still be able to run.
我有一个拦截器,用于检查用户是否已登录,这是我一直希望执行的操作,但是对于某些操作(例如,输入信息),我不希望调用该操作的validate
.
I have an interceptor that checks to see if the user is logged in, which I always want execute, but for some actions (inputting information, for instance), I don't want the action's validate
to be called.
我尝试执行以下操作:
<interceptors>
<interceptor name="bankingAuthenticator"
class="csc309.a4.banking.BankUserAuthenticator"/>
<interceptor-stack name="secureBanking">
<interceptor-ref name="bankingAuthenticator"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureBanking"/>
<action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit">
<result name="success">/banking/Deposit.jsp</result>
<interceptor-ref name="defaultStack">
<param name="workflow.excludeMethods">choose</param>
</interceptor-ref>
</action>
但是它会跳过bankingAuthenticator
拦截器和验证.
But it skips out on both the bankingAuthenticator
interceptor as well as the validation.
推荐答案
我想通了-解决方案如下:
I figured it out--the solution looks like this:
<action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit">
<result name="success">/banking/Deposit.jsp</result>
<interceptor-ref name="secureBanking">
<param name="workflow.excludeMethods">choose</param>
</interceptor-ref>
</action>
拦截器参数可以通过在拦截器名称之前加上参数名称来限制为特定的拦截器.在这种情况下,只有workflow
拦截器会排除choose
方法;其他拦截器仍会为choose
操作方法触发.
Interceptor parameters can be restricted to specific interceptors by prepending the interceptor name to the parameter name. In this case, only the workflow
interceptor will exclude the choose
method; other interceptors will still fire for the choose
action method.
这篇关于Struts 2:仅从defaultStack拦截器中将方法从验证中排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!