title: Struts2 form Validation not working
body: <p>I'm using netbeans 8 with struts 2 xml field validation (tomcat7) to create a web app. form. When I click the submit button without filling in the form the success page appears with no errors for leaving the form blank. Am I missing a step that connects the <code>LoginAction-validation.xml</code> to the form? Maybe I need updated plugins? I have the following in my Libraries folder for form validation:</p>
  
  <p>Struts2 Core 2.3.15 - xwork-core-2.3.15.3.jar</p>
  
  <p>Struts2 Core 2.3.15 - struts2-core-23.15.3.jar</p>
  
  <p>LoginAction.java</p>
  
  <pre><code>package login;
  
  import com.opensymphony.xwork2.ActionSupport;
  
  public class LoginAction extends ActionSupport {
  
      public String getNotes() {
          return notes;
      }
  
      public void setNotes(String notes) {
          this.notes = notes;
      }
  
      public String getOperatingSystem() {
          return operatingSystem;
      }
  
      public void setOperationSystem(String operatingSystem) {
          this.operatingSystem = operatingSystem;
      }
  
      public String getVersion() {
          return version;
      }
  
      public void setVersion(String pass) {
          this.version = version;
      }
      String operatingSystem;
      String version;
      String notes;
  
      @Override
      public String execute(){
            return "SUCCESS";
      }
  }
  </code></pre>
  
  <p>index.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@taglib uri="/struts-tags" prefix="s" %&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Jive&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Code Sample&lt;/h1&gt;       
          &lt;s:form action="LoginAction" method="post"&gt;
                  &lt;s:textfield label="Operating System" name="operatingSystem"/&gt;
                  &lt;s:textfield label="Version" name="version"/&gt;
                   &lt;s:textfield label="Notes" name="notes"/&gt;
                  &lt;s:submit cssClass="btn btn-primary"/&gt;
          &lt;/s:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" 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_3_0.xsd"&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;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>struts.xml</p>
  
  <pre><code>&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;!-- Configuration for the default package. --&gt;
      &lt;package name="default" extends="struts-default"&gt;
          &lt;action name="LoginAction" class="login.LoginAction" method="execute"&gt;
              &lt;result name="SUCCESS"&gt;/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>LoginAction-validation.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 2.3//EN"
  "http://struts.apache.org/dtds/xwork-validator-2.3dtd"&gt;
  
  &lt;validators&gt;
  &lt;field name="operatingSystem"&gt;
      &lt;field-validator type="requiredstring"&gt;
          &lt;message key="errors.required"&gt;Operation System is required.&lt;/message&gt;
      &lt;/field-validator&gt;
  &lt;/field&gt;
  &lt;field name="version"&gt;
      &lt;field-validator type="requiredstring"&gt;
          &lt;message key="errors.required" /&gt;
      &lt;/field-validator&gt;
  &lt;/field&gt;
  &lt;/validators&gt;
  </code></pre>
  
  <p>success.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@taglib uri="/struts-tags" prefix="s" %&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt; Success &lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>error.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Error!&lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>