title: Use of validation interceptor with alias interceptor in struts2
body: <p>I have implemented alias interceptor. Now when i implement the validation interceptor the validation works fine but the error message is not shown. The reason I understand is due to the difference in field name in the action and jsp pages, Request your assistance to fix. </p>
  
  <p>The code listing is as given below.... </p>
  
  <p>The index.jsp file is </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
  pageEncoding="ISO-8859-1"%&gt; 
  &lt;%@ taglib uri="/struts-tags" prefix="s"%&gt; 
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; 
  &lt;html&gt; 
  &lt;head&gt; 
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; 
  &lt;title&gt;Struts 2&lt;/title&gt; 
  &lt;s:head/&gt; 
  &lt;/head&gt; 
  &lt;body&gt; 
  &lt;s:form action="hello"&gt; 
  &lt;s:textfield label="User Name" name="username"/&gt; &lt;br/&gt; 
  &lt;s:textfield label="User password" name="userpwd"/&gt; &lt;br/&gt; 
  &lt;s:textfield label="Field 1" name="scrField1"/&gt; &lt;br/&gt; 
  &lt;s:textfield label="Field 2" name="scrField2"/&gt; &lt;br/&gt; 
  &lt;s:submit value="Say Hello"/&gt; 
  &lt;/s:form&gt; 
  &lt;/body&gt; 
  &lt;/html&gt; 
  </code></pre>
  
  <p>The HelloAction is as given below:</p>
  
  <pre><code>package org.tp.actions; 
  
  import com.opensymphony.xwork2.ActionSupport; 
  
  public class HelloAction extends ActionSupport{ 
  
  private String name; 
  private String password; 
  private String field1; 
  private String field2; 
  
  public String getName() { 
  return name; 
  } 
  
  public void setName(String nm) { 
  this.name = nm; 
  } 
  
  public String getPassword() { 
  return password; 
  } 
  
  public void setPassword(String password) { 
  this.password = password; 
  } 
  
  public String getField1() { 
  System.out.println("inside HelloAction.getField1 field1 =="+field1); 
  return field1; 
  } 
  
  public void setField1(String scrField1) { 
  
  this.field1 = scrField1; 
  System.out.println("inside HelloAction.setField1 field1=="+field1); 
  } 
  
  public String getField2() { 
  System.out.println("inside HelloAction.getField2 field2 =="+field2); 
  return field2; 
  } 
  
  public void setField2(String scrField2) { 
  this.field2 = scrField2; 
  } 
  
  public String execute() throws Exception{ 
  return "success"; 
  } 
  
  } 
  </code></pre>
  
  <p>struts.xml:</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.devMode" value="true" /&gt; 
  &lt;package name="helloworld" extends="struts-default"&gt; 
  &lt;action name="hello" class="org.tp.actions.HelloAction" method="execute"&gt; 
  
  &lt;param name="aliases"&gt;#{ 'username' : 'name','userpwd' : 'password', 'scrField1' : 'field1', 'scrField2' : 'field2'}&lt;/param&gt; 
  
  &lt;interceptor-ref name="alias"&gt; 
  &lt;param name="excludeMethods"&gt;input,back,cancel,browse&lt;/param&gt; 
  &lt;/interceptor-ref&gt;  
  
  &lt;interceptor-ref name="validation"&gt; 
  &lt;param name="excludeMethods"&gt;input,back,cancel,browse&lt;/param&gt; 
  &lt;/interceptor-ref&gt;  
  &lt;interceptor-ref name="workflow"&gt; 
  &lt;param name="excludeMethods"&gt;input,back,cancel,browse&lt;/param&gt; 
  &lt;/interceptor-ref&gt; 
  
  &lt;result name="success"&gt;/MainPage.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>HelloAction-validation is as given below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN" 
  "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"&gt; 
  &lt;validators&gt; 
  &lt;field name="name" &gt; 
  &lt;field-validator type="requiredstring"&gt; 
  &lt;message &gt;User Name is Required.&lt;/message&gt; 
  &lt;/field-validator&gt; 
  &lt;/field&gt; 
  
  &lt;/validators&gt; 
  </code></pre>