• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Action resubmitted with browser's back button

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gurus! There is an action in my Controller class that I don't want it to be reprocessed when the user clicks the back button. To my understanding, a pageflow keeps track of the last action processed when the user leaves it and then comes back using browser's back button. How can I avoid that? Will appreciate, if your answer will be supported with some code.
Thanks.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
You can avoid this using Synchronizer token pattern.
This is how we implemented it in one of the projects.
1) Keep a hidden variable in the HTML form.
2) Assign this variable a value say "val1" and keep the same value in HttpSession. This can be done when you sending the response for the requested action.
3)When the form is submitted, you check the hidden variable value with the one in session. If they are same then process the request and at the same time reset the value in the session.
4) If this doesnt match then it is a attempt of form-resubmission and throw back an error.

Note: You can write a Utility class which generates random numbers which can be used as values. A custom tag can be used to get the value in the JSP and you can use utility class from your code to get the value which is set in the Httpsession object.
Thanks,
Amit
 
Tom Sayer
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I tried almost the same concept but used formbean. Created a hidden variable tried to set its value in jsp to control in controller class. But somehow the following javascript code did not set the field value. Although I tried it before successfully.
document[lookupNameByTagId("formname")][lookupNameByTagId("fieldname")].value = fieldvalue;
OR
document[getNetuiTagName("formname")][getNetuiTagName("fieldname")].value = fieldvalue;
I am using
(netui:anchor action="anAction" onKlick="setValue('${someValue}')")
etc. and have 3 forms in the jsp that might be preventing it to set the values through javascript, technically it should not be the case.
In your solution, I may have to use the same logic, or is there any other way of setting hidden fields value?
 
Tom Sayer
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it:
Used preventDoubleSubmission element in @Jpf.Action and then caught the DoubleSubmitException in @Jpf.Catch annotation etc.
reply
    Bookmark Topic Watch Topic
  • New Topic