On 25-05-2009 at 14:41, Michael Day wrote: > One of my use cases is order checkout. The last thing I want to do is > show an error page to the user, even if they are dumb enough to submit > twice.
I can sympathise with that: even an application message (not an error) can be imtimidatng here. > How do you recognize the second submission? Are you using a hidden > token in the form? Just checking whether the same action is called > twice in a certain period of time isn't robust enough. Sometimes > ActionBean execution could take longer than a few seconds. One way is to always show a details page before an action. Then, displaying the details page would add a token to the session and in a hidden field. Upon submit, you check if the token is available in the session. If so, remove it and process the request. If not, the request is already (being) processed. > I'm already doing exactly as you said (skip processing and redirect to > result page immediately) in my submit handler by looking at the status > of the order. If the status is Submitted, I'm just showing the result > page. But for this to work properly, I have to obtain a pessimistic > lock on the order at the beginning of the request. Or, update the order status in a transaction first, and then process the order in a second transaction afterwards. Especially with a transaction isolation of "serializable", this will ensure a second request can only read the updated order status. > I'm curious how amazon handles this. I tried double-submitting some > forms on their site, but it seems like they either somehow abort all > but the last request or have a filter that caches the first submission > and shows it on subsequent requests. I'm not sure how they would have > a filter, though, because there is no hidden token in the form. Instead of a token, you can also hash the request. This would eliminate the need to send a token to the browser. Add to that that the hash would also include the session (with data like the last page view for an ActionBean), and duplicate requests will have identical hashes. Oscar -- ,-_ Oscar Westra van holthe - Kind http://www.xs4all.nl/~kindop/ /() ) (__ ( Clearly the Bush Presidency was divine punishment for the sinful =/ () ways of the USA and the West that tagged along. ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ Stripes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/stripes-users
