如何在 Struts 2 中通过 XML 配置来配置 @SkipValidation [英] How to configure @SkipValidation by XML configuration in Struts 2

查看:32
本文介绍了如何在 Struts 2 中通过 XML 配置来配置 @SkipValidation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Struts 2 中,

In Struts 2,

我试图跳过基于 XML 配置的方法验证.根据我的应用程序,我不能使用注释.所以我不能使用 @SkipValidation 注释.有什么替代方法吗?

I am trying to skip validation on method base on XML configuration. As per my application I can not use annotation. So I cannot use @SkipValidation annotation. Is there any alternative for this?

我有一个动作类,它有五个方法 createupdatedeletesearch 和 <代码>查看.我只想验证两种方法 createupdate.

I have one action class which has five methods create, update, delete, search, and view. I want to validate only two methods create and update.

推荐答案

你应该在struts.xml包中配置拦截器

You should configure in the struts.xml package with interceptors

<interceptors>
  <interceptor-stack name="validateWorkflowStack">
    <interceptor-ref name="basicStack"/>
<!-- ... whatever interceptors -->
    <interceptor-ref name="validation">
      <param name="excludeMethods">delete, search, view</param>
    </interceptor-ref>
    <interceptor-ref name="workflow"/>
  </interceptor-stack>
</interceptors>

然后使用动作配置

<action name="create" class="your.package.CreateAction" method="create">
    <result name="input">/path/to/form.jsp</result>
    <interceptor-ref name="validateWorkflowStack"/>
</action>

将拦截器应用于每个动作,该动作具有在动作上显式引用或通过包上的 <default-interceptor-ref 隐式引用的验证拦截器.

apply interceptor to each action that has a validation interceptor referenced explicitly on action or implicitly via <default-interceptor-ref on the package.

这篇关于如何在 Struts 2 中通过 XML 配置来配置 @SkipValidation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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