Struts 2:从 defaultStack 拦截器的验证中排除方法 [英] Struts 2: excluding method from validation from just the defaultStack interceptor

查看:19
本文介绍了Struts 2:从 defaultStack 拦截器的验证中排除方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆