It's kind of a pain but the best way I know is to do it this way.

In the form itself, have a hidden variable... we'll call it "uniqueid".
This needs to be dynamically generated every time the form is called from
the server, and the value must be a unique ID... I'm lazy so I use
System.currentTimeMillis().

<input type="hidden" name="uniqueid" value="<%= System.currentTimeMillis()
%>">

On the page that the form submits to, you'll keep a set of used uniqueid's
in a hashtable in the session.  First see if the uniqueid that was just
passed does exist in the hashtable; if so, then you know that this exact
form has already been submitted and processed, and you can act accordingly.
If not, then process the form and store the uniqueid in the hashtable.

Make sense?

-jmc

-----Original Message-----
From: Vince Chau [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 13, 2001 11:50 AM
To: [EMAIL PROTECTED]
Subject: How to prevent data from being submited twice in a JSP page?


Hi all

As the subject suggests what is the easiest way to implement this?
Everytime I reload my page, my data gets resubmitted, how do I prevent
this?
Here is my sample code
<% String myComments = request.getParameter("COMMENTS"); %>
<% bean0.setConnection(); %>
<% if (myComments != null)
   {
     bean0.insertEntry(myComments);
     }
   %>
<%=bean0.getShow() %>

Is there some sort of flag I need to tell my JSP page to be aware off?
So it knows not to resubmit the data, or is there a way of reseting
parameters?

Thans in advance

Vince

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to