JavaRanch Home
 
Front Page FAQs Ranchers Categories Recent Changes To Do Upload

How To Prevent Multiple Form Submits   



(Based on Junilu's nice description at http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=003395)

On initial request:

  1. call saveToken(request) in your Action class
  2. forward to the JSP displaying the form

On form submit:

  1. have the Action check if isTokenValid(request)
  2. if true, process request then call resetToken(); otherwise, we're dealing with a double-submit and will skip processing it.

What's happening under the hood:

  • Struts will generate a unique value (the token) and keep it in the session context
  • When the JSP is rendered, Struts inserts the token as a hidden field
  • The hidden field token is submitted along with the rest of the form and isValidToken() checks the value that came in with the current request against the value that was saved in the session context by the most recent saveToken() call. If the two token values match, the submission is valid.

<< Back to StrutsFaq

Front Page FAQs Ranchers Categories Recent Changes To Do Upload
Last Edited: 03 August 2004 What's Changed?
 
Copyright © 1998-2008 Paul Wheaton | Home | Contact Us | Privacy | Register