I am building a web application using Servlet 2.5, and I have encountered a need to make it so that a user cannot click a button and do an action and then press F5/Refresh and do the action again.
Two ways that I have pondered about to combat this (but not really given much thought yet; thinking it’s best to ask here first):
- When an action has been done, I call on a redirect, effectively clearing any query parameters
- When an action has been done, I add a randomized hash and check on the next entry if it has changed or not? (not sure how to know if the next action is a refresh or an actual new request here, though)
Or is there a more simple/standardized way of doing this either with Tomcat/etc or some commons library?
Your first idea is correct. The pattern is called redirect after post. If you use any advanced web development framework it should support this out of the box.
You should use the HTTP verbs correctly. If it is a
HTTP GETit should be no problem to call it more than once.