Hi Matt,
If your customer data includes fields that are unique across customers
(sometimes email address has this property), add a uniqueness constraint on
the appropriate column in the database. JDBC will throw an exception if
someone re-submits customer data- thereby attempting to insert a duplicate
row.
Otherwise, the following procedure can solve it at the application level.
1. When you send the form down (in customerMaint.jsp), include a hidden
field in the form called SubmitTicket whose value is a large random number.
2. In SaveServlet, pull out the SubmitTicket from the submitted data.
3. If you don't get a SubmitTicket (which will happen if someone clicks in
the URL bar and presses return), send an appropriate error response. In this
case, it's probably a redirect to customerMaint.jsp.
4. If you get a SubmitTicket, check to see whether a session state variable
called SubmittedTickets contains the SubmitTicket number.
5. If SubmittedTickets doesn't contain SubmitTicket, append the number plus
a space to SubmittedTickets (the space ensures you don't confound the text
search when one user has to enter multiple customers). Continue handling the
request normally.
6. If SubmittedTickets contains SubmitTicket, this signals a double submit.
Handle the error.
Cheers,
Jonah
> -----Original Message-----
> From: Matt Krevs [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 12, 2000 7:11 PM
> To: Orion-Interest
> Subject: forward Vs redirect. Stopping multiple form submits
>
>
> I have an intranet website that has a lot of display/edit/delete
> functionality using forms.
>
> For example - to create a new customer the user would open
> customerMaint.jsp, enter the details and click submit.
>
> Clicking submit calls a servlet (lets call it SaveServlet)
> that saves the
> details. This servlet then forwards to customerMaint.jsp to
> display the
> saved details.
>
> Unfortunately (for me anyway), after the forward, the URL in
> the browser is
> still SaveServlet. Consequently, if the user refreshes the
> browser (hits F5
> in IE), the form is resubmitted and hey presto we now have 2
> customers with
> the same details.
>
> I'm sure I'm not the only person to have this problem. How are others
> handling this situation?
>
> ie open page -> submit form -> forward to initial page with
> saved details ->
> stop the user from resubmitting the original form.
>
> I have played around with sendredirect but there are quite a
> few limitations
> I cant get around - namely
>
> 1. its slower than doing a forward
> 2. the request parameters arent automatically passed to the
> sendRedirected
> page. You have to do it manually.
> 3. if you have a very large parameter there is no nice way to
> send to to the
> sendRedirected page (eg like a POST). For example we save details by
> building up an xml string and sending it as a form parameter.
> This string
> can get very long and cant really be tacked on to the end of the query
> string in the url when sendRedirect is called.
>
> Anyone have any bright ideas? Any help appreciated.
>
> Thanks
> Matt
>
>