aspose file tools*
The moose likes Struts and the fly likes Form Tokens Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Tokens" Watch "Form Tokens" New topic
Author

Form Tokens

Nicolas Flammel
Ranch Hand

Joined: May 05, 2004
Posts: 32
I have a jsp form which has two html:submit buttons 'save' and 'save and add more'. Both submit the form data except that the save button loads another page and save and add more save the data but remains on that very page for more data to be inserted if needed.

I have used saveToken when coming to add page(which has these two buttons) to prevent resubmission of data when going back and clicking on save or when pressing F5.

How do I go about doing the same if one clicks on save and add more button.
If i use tokens then i am not able to save data for the second time when clicked on save and add more as the same page loads AND if i don't use token then pressing F5 after saving data for the first time would re submit the form and there would be duplicate data?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Would resetToken on each call rectify this issue?


A good workman is known by his tools.
Nicolas Flammel
Ranch Hand

Joined: May 05, 2004
Posts: 32
resetToken after performing the insertion does the work for first time only. After that even the save button doesn't submit the form data nor does save and add more.
forum guest
Greenhorn

Joined: Mar 24, 2003
Posts: 16
Sounds like you are only reseting the Token in the prepare action that forwards to the JSP.


What you need is to reset and save the Token in the Action that the form submits to.

//save the new token
resetToken(request);
saveToken(request);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Form Tokens