Search code examples
javajakarta-eeservletsstrutsstruts-1

How to pass a form variable from one action to another action class in Struts 1.2


How to pass a form variable from one action to another action?

Here is the example: (MyContractForm is in request scope)

MyContractForm.java
{
   private Calendar creationDate = Calendar.getInstance();
}
MyContractAction@method1
{
    myContractForm.setCreationDate(Calendar.getInstance());
    forward to myContract.Jsp
}
MyContract.JSP
{
   <script type="text/javascript">
   //For a button - javascript
   function getStatus()
   {
       document.myContractForm.dispatch.value = "method2";
       document.myContractForm.submit();
   }
   </script>
   <html:form>
       <button type="button" id="btnStatus" onclick="getStatus()">Get Status</button>
   </html:form>
}
MyContractAction@method2
{
    // should be able to access creationDate value that was set in method1
}

How can we achieve this?


Solution

  • you could use request object to pass values across classes and JSPs in struts

    method1:

    request.setAttribute("attr","value");
    

    method2:

    Object obj=request.getAttribute("attr");