Struts 2 default XML validation tutorial


            In this tutorial we'll cover how to validate a user's input in form fields using Struts 2's XML validation methodology. In the Form Validation tutorial we discussed validating a user's input using a separate XML validation file gives you the ability to use validators built-in to the Struts 2 framework.

        Create a xml file in the same directory where you controller are placed using the name conversion ControllerName-validation.xml

        Example if your controller name is then your xml name should be LoginController-validation.xml


<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"

<field name="uname">
    <field-validator type="requiredstring">
       <message>User Name is required.</message>

<field name="pass">
    <field-validator type="requiredstring">
       <message>Password is required.</message>

<field name="mail">
    <field-validator type="requiredstring">
    <message>email is required</message>

    <field-validator type="email">
    <message>enter valid email id</message>






        Struts 2 xml vaildation war

        Struts 2 xml vaildation maven zip

Related Post