Hi,

In such cases, what I do is to use the "POST" method in my form so when
the user hits reload he will be asked whether he really wants to submit
the form data again. That's what I think the post method was designed
for. You can still get in trouble if they hit the reload button and
answer "yes" but with http redirect it will happen the same if they hit
the back button and then resubmit the form. So if you want to be really
sure they don't submit the data twice, then you'd better check in your
database if the data was there before inserting it, using some of the
methods that Hans or Craig suggested. My philosophy is to warn users and
help them in the normal operation, but if they want to voluntarily hit
their head against a wall after your warnings, it takes too much time
and effort to prevent them from doing so. So I just make sure that the
data in the database is consistent.
Just my 2c,
Dan
-------------------------------------------
Daniel Lopez Janariz ([EMAIL PROTECTED])
Web Services
Computer Center
Balearic Islands University
-------------------------------------------

Hans Bergsten wrote:
>
> "Wang, Dapeng" wrote:
> >
> > Hi,
> >
> > sorry for the belated response. I'm facing the same problem in the
> > development. I am aware that a HTTP redirect requires one extra round trip
> > to client, but RequestDispatcher.forward or jsp:forward may bring problems
> > with browser reload. If a user fills in a form and pushes submit, one record
> > (e.g an order item) will be inserted in the database by a servlet or a jsp,
> > and the request is forwarded to another JSP(e.g. to show the order). At that
> > moment if the browser reload button is pressed, the formeer servlet or JSP
> > will be invoked again, which tries to insert the same record again in the
> > database. So I think HTTP redirect should be used to prevent such duplicate
> > data problem. Any comment?
>
> Yes, I agree. In situations like this I usually redirect to a page showing
> the result. You could, of course, use forward and guard against duplicate
> submits by keeping some sort of transaction ID (e.g. as a hidden field in the
> form) that you verify is not used already before you update the database. But
> redirecting is easier and the extra round trip is often worth it IMHO.
>
> Hans
> --
> Hans Bergsten           [EMAIL PROTECTED]
> Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to