title: Struts2- Persistence of objects values between different actions in the same Action class
body: <p><strong>Scenario:</strong> On click of a <code>Submit</code> button I have unmarshalled the XML to Java and then displaying the Java objects(created a formbean and mapped the JAXB java Objects to this formbean - <code>PolicyForm</code> and using this formbean to display in JSP) in the JSP. This is working fine.</p>
  
  <p><strong>Issue:</strong> I have one more button -<code>Calculate</code> on the same page with in the same form of <code>Submit</code> button. On click of the 'Calculate' button I need to get the <code>acordform</code> values which was unmarshalled during the click of <code>Submit</code> button. Here I am not able to get the <code>acordform</code> values instead I am getting the new object of <code>acordform</code>.</p>
  
  <p>When I have googled I see - Struts 2 doesn't have thread-safety issues as "Action objects are instantiated for each request".</p>
  
  <p>Please let me know here when I am sending the request again is the Action object- <code>acordform</code> being instantiated everytime? If yes, how can I avoid this? Since I need the <code>acordform</code>object values even in the next request too.</p>
  
  <p><strong>Action Class:</strong></p>
  
  <pre><code>public class RateAction extends ActionSupport implements
          ServletRequestAware,SessionAware {
  
      /* ... */
  
      // ACORD xml form bean
      private ACORD acordform = new ACORD();
  
      //To display the values in the JSP
      private PolicyForm policyForm;
  
      public ACORD getAcordform() {
          return acordform;
      }
  
      public void setAcordform(ACORD acordform) {
          this.acordform = acordform;
      }
  
      public String doSubmit() {
         /*...Unmatshalling from XML to Java -acordform is done..*/
      }
  
      public String doRateSubmimt() 
      {
         /*..trying to get the acordform values which are being set 
           previously in doSubmit() method...*/
      }
  }
  </code></pre>
  
  <p><strong>Strust.xml:</strong></p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;struts&gt;
  &lt;constant name="struts.enable.DynamicMethodInvocation" value="false" /&gt;
  &lt;constant name="struts.devMode" value="true" /&gt;
  &lt;constant name="struts.custom.i18n.resources" value="ApplicationResources" /&gt;
  &lt;package name="default" extends="struts-default" namespace="/" &gt;
  
      &lt;action name="fileUploadAction"
          class="com.main.common.action.RateAction" &gt;
          &lt;interceptor-ref name="fileUpload"&gt;
              &lt;param name="allowedTypes"&gt;text/xml&lt;/param&gt;
          &lt;/interceptor-ref&gt;
          &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
               &lt;interceptor-ref name="params"/&gt;   
               &lt;interceptor-ref name="prepare"/&gt;   
               &lt;interceptor-ref name="basicStack"/&gt; 
           &lt;result name="success"&gt;First.jsp&lt;/result&gt;
           &lt;result name="input"&gt;First.jsp&lt;/result&gt;
      &lt;/action&gt;
  
      &lt;action name="submitAction" class="com.main.common.action.RateAction" method="doSubmit"&gt;
      &lt;result name="success"&gt;First.jsp&lt;/result&gt;
      &lt;/action&gt;
      &lt;action name="rateAction" class="com.main.common.action.RateAction" method="doRateSubmit"&gt;
          &lt;result name="success"&gt;First.jsp&lt;/result&gt;
      &lt;/action&gt;
  &lt;/package&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>JSP:</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:form id="rtr" action="fileUploadAction" method="POST"
      enctype="multipart/form-data"&gt;
      &lt;table border="0" cellspacing="0" cellpadding="0"&gt;
          &lt;tr&gt;
              &lt;s:file name="uploadFile" label="Upload Request XML" /&gt;
              &lt;s:submit value="Submit" action="submitAction" onclick="displayDetails();" /&gt; 
              &lt;s:hidden name="submitSuccess" /&gt;
              &lt;s:submit value="Calculate" action="rateAction" /&gt; 
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/s:form&gt;
  </code></pre>