How to validate fields properly in Struts 2

后端 未结 2 416
感情败类
感情败类 2021-01-26 00:15

I would like to know what I\'m doing wrong here :


    
        

        
相关标签:
2条回答
  • 2021-01-26 01:04

    If you wanna skip validation to any action method use @SkipValidation annotation.

    @SkipValidation
    public String yourMethod {
        ...         
        return "input";
    }
    
    0 讨论(0)
  • 2021-01-26 01:16

    The name is case sensitive, you should use

    <field-validator type="requiredstring" short-circuit="true">
    

    The data can be validated after it's populated to the action. Either you do it in a declarative way using *-validation.xml or programmatically via validate().

    You can configure validation interceptor to choose between these two ways, because by default validate() runs after declarative validations are done even if they are short-circuit.

    Consider using alwaysInvokeValidate parameter. If you use aliased validation files as ActionClass-alias-validation.xml then validations are run for this action alias only. You can use this alias when you map your action methods.

    0 讨论(0)
提交回复
热议问题