3

I have a form that is submitted to a details page where I have a button. I put in place an action in my mapping file to link an action to that button which should send the user back to the form and empty it.

I can redirect it correctly but the form still shows the sent values.

<action
   ...
   <forward name="goBack" path="/form.jsp" />
</action>

So, how can I go back to an empty form with action mapping tags ?

Thank you.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Michael
  • 31
  • 2

2 Answers2

2

If I understand your question correctly, this is what you want to do: You want to display an empty form to the user, when a user clicks on the button. You can try to set the form to null in your action class before returning from the method.

So when you click the button, if it calls a method emptyForm() in your action class, and your form name is myForm, do the following

public ActionForward emptyForm(ActionMapping a, ActionForm myForm, HttpServletRequest Req, HttpservletResponse res){

myForm=null; 
...
..
}
Susie
  • 5,038
  • 10
  • 53
  • 74
1

You could do a redirect to the action that have as a result the jsp with the form. A simple link to that action should work:

<a href="actionWithForm"> GoBack </a>
Atropo
  • 12,231
  • 6
  • 49
  • 62
  • There is no way to do it properly in the mapping file ? The idea is to keep all the redirections in one and single place. – Michael Dec 07 '12 at 10:25
  • [Redirect action](http://struts.apache.org/2.1.6/docs/redirect-action-result.html) should work – Atropo Dec 07 '12 at 10:43