title: Retaining values between multiple JSPs and Actions in Struts 2
body: <p>My Struts project structure is as follows:</p>
  <p><code>page1</code>-&gt;<code>action1</code>-&gt;<code>page2</code>-&gt;<code>action2</code>-&gt;<code>page3</code></p>
  <p>What i need is for a value i entered in an input tag in <code>page1</code> to be accessed in <code>action2</code>.</p>
  <p><strong>Here is my code:</strong></p>
  <p><strong>page1:</strong></p>
  <pre class="lang-jsp prettyprint-override"><code>&lt;div class = &quot;container&quot;&gt;
      &lt;s:form id = &quot;idinput&quot; method = &quot;post&quot; action = &quot;idEntered&quot;&gt;
          Enter id: &lt;input id = &quot;txtid&quot; name = &quot;txtid&quot; type = &quot;text&quot; /&gt;
          &lt;input id = &quot;cmdsubmit&quot; name = &quot;cmdsubmit&quot; type = &quot;submit&quot; value = &quot;enter details&quot; /&gt;
      &lt;/s:form&gt; 
  &lt;/div&gt;
  </code></pre>
  <p><strong>action1:</strong></p>
  <pre class="lang-java prettyprint-override"><code>public class AddId extends ActionSupport {
  
  private int txtid;
      //getter and setter
  
  @Override
  public String execute() throws Exception {      
      return &quot;success&quot;;
  }   
  }
  </code></pre>
  <p><strong>page2:</strong></p>
  <pre class="lang-jsp prettyprint-override"><code>&lt;div class = &quot;container&quot;&gt;
      &lt;s:form id = &quot;formvalues&quot; method = &quot;post&quot; action = &quot;formEntered&quot;&gt;
          &lt;p&gt;Your id entered is: &lt;s:property value = &quot;txtid&quot; /&gt;&lt;/p&gt;
          First name: &lt;input id = &quot;txtfname&quot; name = &quot;txtfname&quot; type = &quot;text&quot; /&gt;
          Last name: &lt;input id = &quot;txtlname&quot; name = &quot;txtlname&quot; type = &quot;text&quot; /&gt;
          Age: &lt;input id = &quot;txtage&quot; name = &quot;txtage&quot; type = &quot;text&quot; /&gt;
          &lt;input id = &quot;cmdform&quot; name = &quot;cmdform&quot; type = &quot;submit&quot; value = &quot;submit form&quot; /&gt;     
      &lt;/s:form&gt;
  &lt;/div&gt;
  </code></pre>
  <p><strong>action2:</strong></p>
  <pre class="lang-javq prettyprint-override"><code>public class AddForm extends ActionSupport {    
      private String txtfname;
  private String txtlname;
  private int txtage;
  private int txtid;
        //getters and setters 
  
  @Override
  public String execute() throws Exception {
      
      return &quot;success&quot;;
  }
  }
  </code></pre>
  <p>and displaying everything in</p>
  <p><strong>page3:</strong></p>
  <pre class="lang-jsp prettyprint-override"><code>&lt;div class = &quot;container&quot;&gt;
      ID: &lt;s:property value = &quot;txtid&quot; /&gt;&lt;br&gt;
      first name: &lt;s:property value = &quot;txtfname&quot; /&gt;&lt;br&gt;
      last name: &lt;s:property value = &quot;txtlname&quot; /&gt;&lt;br&gt;
      age: &lt;s:property value = &quot;txtage&quot; /&gt;
  &lt;/div&gt;
  </code></pre>
  <p>this is where I face a problem as <code>txtid</code> is displayed as <code>null</code>, from which I inferred that the value is not passed from <code>page2</code> to <code>action2</code></p>
  <p>a solution i have come up with is to use</p>
  <pre class="lang-jsp prettyprint-override"><code>&lt;s:hidden value = &quot;%{txtid}&quot; name = &quot;txtid2 /&gt; 
  </code></pre>
  <p>in my form in <code>page2</code> which will allow me to use the value of <code>txtid</code> as <code>txtid2</code> in <code>action2</code>, this however seems more like a hack than an actual solution, so any other suggestions are welcome.</p>