title: Struts2 - Access from JSP to Action variables
body: <p>I have got a little problem with Struts2, and I don't know why it doesn't work ...</p>
  
  <p>I want to pass 2 variables between two JSP, via an Action class :</p>
  
  <p><strong>view1.jsp :</strong></p>
  
  <pre><code>&lt;s:form action="myAction"&gt;
     &lt;input id="var1" name="var1" type="text" /&gt;
     &lt;input id="var2" name="var2" type="text" /&gt;
     &lt;button type="submit"&gt; Ok &lt;/button&gt;
  &lt;/s:form&gt;
  </code></pre>
  
  <p><em>-> var1 and var2 are the variables that I want to pass to the Action class</em></p>
  
  <p><strong>struts.xml:</strong></p>
  
  <pre><code>&lt;action name="myAction" class="MyAction" method="execute"&gt;
      &lt;result name="success"&gt;view2.jsp&lt;/result&gt;
  &lt;/action&gt;
  </code></pre>
  
  <p><strong>Action.java :</strong></p>
  
  <pre><code>public class MyAction extends DefaultActionSupport
  {
      private String var1;
      private String var2;
  
  public String execute() throws Exception
  {
      // ... Some actions ...
      return SUCCESS;
  }
  
  // Getters &amp; Setters for var1 and var2 (generated by Eclipse)
  public String getVar1()
  {
      return var1;
  }
  
  public void setVar1(String var1)
  {
      this.var1 = var1;
  }
  
  public String getVar2()
  {
      return var2;
  }
  
  public void setVar2(String var2)
  {
      this.var2 = var2;
  }
  </code></pre>
  
  <p><em>-> This works correctly ; if I put "System.out.print" with the getters, it shows me the good values of var1 (content1) and var2 (content2)</em></p>
  
  <p><strong>view2.jsp :</strong></p>
  
  <pre><code>Values of var1 = &lt;s:property value="var1" /&gt;
  Values of var2 = &lt;s:property value="var2" /&gt;
  
  Textfield with var1 in default-value : &lt;s:textfield value="%{var1}" /&gt;
  Textfield with var2 in default-value : &lt;s:textfield value="%{var2}" /&gt;
  </code></pre>
  
  <p>-> There is a problem here :
  I can't get the content of var1 and var2 !<br/>
  -> <code>&lt;s:property value="var1" /&gt;</code> and <code>&lt;s:textfield value="%{var1}</code> are returning "null"</p>
  
  <p>Where is my error ? I don't understand ... I followed what the others said on the internet ...</p>
  
  <p>Thank you !</p>