Struts2 validators with xml configuration doesn't work
<p>I am a beginner of Struts2. When I've tried to use the validation framework to validate the input data from the form, I have encountered a problem: the validators don't work at all. I can get the page which is supposed to be returned when you pass the validation with nothing being entered.</p>

<p>The following is my code and package, I have searched it on StackOverFlow, but I have not found a solution that solve my problem. </p>

<p><img src="https://i.stack.imgur.com/Ap7CK.jpg" alt="The structure of the project"></p>

<p>Register.java</p>

<pre><code>package validation;
</code></pre>



<pre class="lang-java prettyprint-override"><code>/**
 * Created by xiangang.wei on 2016/10/26.
 */
public class Register {
    private String userName;
    private String password;
    private String rpassword;
    private int age;
    private int phone;
    private String email;

    public String getRpassword() {
        return rpassword;
    }

    public void setRpassword(String rpassword) {
        this.rpassword = rpassword;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUserName() {

        return userName;
    }

    public String getPassword() {
        return password;
    }

    public int getAge() {
        return age;
    }

    public int getPhone() {
        return phone;
    }

    public String getEmail() {
        return email;
    }

    public String execute(){
        return "success";
    }
}
</code></pre>

<p>Register-validation.xml</p>



<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE validators PUBLIC
        "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
        "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"&gt;


 &lt;validators&gt;
    &lt;validator type="stringlength" &gt;
        &lt;param name="fieldName"&gt;userName&lt;/param&gt;
        &lt;param name="maxLength"&gt;10&lt;/param&gt;
        &lt;param name="minLength"&gt;1&lt;/param&gt;
        &lt;message&gt;The length is wrong!&lt;/message&gt;
    &lt;/validator&gt;
    &lt;validator type="fieldexpression"&gt;
        &lt;param name="fieldName"&gt;password&lt;/param&gt;
        &lt;param name="expression"&gt;![CDATA[password == rpassword]]&lt;/param&gt;
        &lt;message&gt;The password is not the same!&lt;/message&gt;
    &lt;/validator&gt;
    &lt;validator type="int"&gt;
        &lt;param name="fieldName"&gt;age&lt;/param&gt;
        &lt;param name="max"&gt;130&lt;/param&gt;
        &lt;param name="min"&gt;1&lt;/param&gt;
        &lt;message&gt;The age must be 1 - 130&lt;/message&gt;
    &lt;/validator&gt;
    &lt;validator type="email"&gt;
        &lt;param name="fieldName"&gt;email&lt;/param&gt;
        &lt;message&gt; Please enter a valid email address!&lt;/message&gt;
    &lt;/validator&gt;
&lt;/validators&gt;
</code></pre>

<p>struts.xml</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd"&gt;

&lt;struts&gt;
&lt;package name="register" extends="struts-default" namespace="/"&gt;
    &lt;action name="register" class="validation.Register"&gt;
        &lt;result name="success"&gt;/register-view/register-success.jsp&lt;/result&gt;
        &lt;result name="input"&gt;/index.jsp&lt;/result&gt;
    &lt;/action&gt;
&lt;/package&gt;
&lt;/struts&gt;
</code></pre>

<p>web.xml</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1"&gt;


    &lt;filter&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;filter-class&gt;org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
&lt;/web-app&gt;
</code></pre>

<p>build.gradle</p>

<pre class="lang-xml prettyprint-override"><code>group 'xiangang.wei'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'war'

sourceCompatibility = 1.8

repositories {
    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'org.apache.struts:struts2-core:2.5'
}
</code></pre>

<p>index.jsp</p>

<pre class="lang-xml prettyprint-override"><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
&lt;%--
  Created by IntelliJ IDEA.
  User: xiangang.wei
  Date: 2016/10/26
  Time: 11:19
  To change this template use File | Settings | File Templates.
--%&gt;
&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;User Register！&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;s:form action="register" method="POST"&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:textfield label="Name" name="userName"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:password label="Password" name="password"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:password label="Confirm Password" name="rpassword"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:textfield label="age" name="age"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:textfield label="Phone" name="phone"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;s:textfield label="Email" name="email"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;
                &lt;s:submit value="Submit"/&gt;
            &lt;/td&gt;
            &lt;td&gt;
                &lt;s:reset value="Reset"/&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/s:form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>register-success.jsp</p>

<pre class="lang-xml prettyprint-override"><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
&lt;%--
  Created by IntelliJ IDEA.
  User: xiangang.wei
  Date: 2016/10/26
  Time: 13:55
  To change this template use File | Settings | File Templates.
--%&gt;
&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;注册成功！&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h3&gt;Congratulation!&lt;/h3&gt;
&lt;hr/&gt;
&lt;h5&gt;Here is your registering info：&lt;/h5&gt;
Name：&lt;s:property value="userName"/&gt;
Password：&lt;s:property value="password"/&gt;
Age：&lt;s:property value="age"/&gt;
E-mail：&lt;s:property value="email"/&gt;
Phone Number：&lt;s:property value="phone"/&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>