title: Struts2 'Required' field Validation Interceptors not working
body: <p>Building a login application (In Netbeans 731) which basically ensures non blank values for username and pw. The application runs fine except the validation doesn't work, so even if the user enters blank values they are taken to the <code>Thanks.jsp</code> page. After trying to build it as a Netbeans web app, I have rebuilt this application using Maven, with the following directory structure:  </p>
  
  <p><img src="https://i.stack.imgur.com/CfhXJ.jpg" alt="enter image description here"></p>
  
  <p>The generated war file is: </p>
  
  <p><img src="https://i.stack.imgur.com/vqJbT.jpg" alt="enter image description here"></p>
  
  <p><strong><code>pom.xml</code>:</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.manaar&lt;/groupId&gt;
  &lt;artifactId&gt;Maven8a2&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;name&gt;Maven8a2&lt;/name&gt;
  
  &lt;properties&gt;
      &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
          &lt;version&gt;6.0&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.struts&lt;/groupId&gt;
          &lt;artifactId&gt;struts2-core&lt;/artifactId&gt;
          &lt;version&gt;2.3.15.1&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.14&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.3.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.6&lt;/source&gt;
                  &lt;target&gt;1.6&lt;/target&gt;
                  &lt;compilerArguments&gt;
                      &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                  &lt;/compilerArguments&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;validate&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;copy&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                          &lt;silent&gt;true&lt;/silent&gt;
                          &lt;artifactItems&gt;
                              &lt;artifactItem&gt;
                                  &lt;groupId&gt;javax&lt;/groupId&gt;
                                  &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                  &lt;version&gt;6.0&lt;/version&gt;
                                  &lt;type&gt;jar&lt;/type&gt;
                              &lt;/artifactItem&gt;
                          &lt;/artifactItems&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong><code>web/jsp/Required.jsp</code>:</strong></p>
  
  <pre><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;required Validator Example&lt;/title&gt;
  &lt;style type="text/css"&gt;@import url(css/main.css);&lt;/style&gt;
  &lt;style&gt;
    .errorMessage {
  color:red;
   }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="global" style="width:350px"&gt;
  &lt;h3&gt;Enter user name and password&lt;/h3&gt;
  &lt;s:fielderror/&gt;
  &lt;s:form action="Required2"&gt;
  &lt;s:textfield name="userName" label="User Name"/&gt;
  
      &lt;s:password name="password" label="Password"/&gt;
      &lt;s:submit/&gt;
  &lt;/s:form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><code>web/jsp/Thanks.jsp</code>:</strong></p>
  
  <pre><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Thank you&lt;/title&gt;
  &lt;style type="text/css"&gt;@import url(css/main.css);&lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="global"&gt;
  Thank you
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><code>WEB-INF/classes/app08a/RequiredTestAction.class</code>:</strong></p>
  
  <pre><code>package app08a;
  import com.opensymphony.xwork2.ActionSupport;
  
  public class RequiredTestAction extends ActionSupport {
  private String userName;
  private String password;
  public String getPassword() {
      return password;
  }
  public void setPassword(String password) {
      this.password = password;
  }
  public String getUserName() {
      return userName;
  }
  public void setUserName(String userName) {
      this.userName = userName;
  }
  }
  </code></pre>
  
  <p><strong><code>WEB-INF/classes/app08a/RequiredTestAction-validation.xml</code>:</strong></p>
  
  <pre><code>&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;field name="userName"&gt;
      &lt;field-validator type="requiredstring"&gt;
          &lt;message&gt;Please enter a user name&lt;/message&gt;
      &lt;/field-validator&gt;
  &lt;/field&gt;
  &lt;field name="password"&gt;
      &lt;field-validator type="requiredstring"&gt;
          &lt;message&gt;Please enter a password&lt;/message&gt;
      &lt;/field-validator&gt;
  &lt;/field&gt;
  &lt;/validators&gt;
  </code></pre>
  
  <p><strong><code>WEB-INF/classes/struts.xml</code>:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
  &lt;constant name="struts.enable.DynamicMethodInvocation" value="false" /&gt;
  &lt;constant name="struts.devMode" value="true" /&gt;
  
  &lt;package name="app08a" extends="struts-default"&gt;
  
      &lt;action name="Required1"&gt;
          &lt;result&gt;/jsp/Required.jsp&lt;/result&gt;
      &lt;/action&gt;
      &lt;action name="Required2" class="app08a.RequiredTestAction"&gt;
          &lt;result name="input"&gt;/jsp/Required.jsp&lt;/result&gt;
          &lt;result&gt;/jsp/Thanks.jsp&lt;/result&gt;
      &lt;/action&gt;
  
  &lt;/package&gt;
  
  &lt;/struts&gt;
  </code></pre>
  
  <p><strong><code>WEB-INF/web.xml</code>:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee    /web-app_2_5.xsd"
  version="2.5"&gt; 
  
  &lt;filter&gt;
      &lt;filter-name&gt;struts2&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.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;!-- Restrict direct access to JSPs. 
       For the security constraint to work, the auth-constraint
       and login-config elements must be present --&gt;
  &lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;JSPs&lt;/web-resource-name&gt;
          &lt;url-pattern&gt;/jsp/*&lt;/url-pattern&gt;
      &lt;/web-resource-collection&gt;
      &lt;auth-constraint/&gt;
  &lt;/security-constraint&gt;
  
  &lt;login-config&gt;
      &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
  &lt;/login-config&gt;
  &lt;/web-app&gt; 
  </code></pre>
  
  <p>When I built this application manually (with Maven) it gave a stack trace due to wrong version of DTD tags. I no longer get this error after building the application using Maven. </p>
  
  <p>When running this application I call the Required1.action. Even if I do not enter a password it skips straight to Action2 and the validation interceptor (<code>RequiredTestAction-validation.xml</code>) does not seem to be working. </p>