Browser refresh problem...

Hi all,
 I have added code with question.  When i press refresh button, it resends data to server, which causes duplicate entries in previous comments text area. I am using Tomcat server. Please let me know if there is some way i can fix this problem.
Thanks in advance,
<%@ page import="*"%>
  java.util.Date date = new java.util.Date();
  String text = request.getParameter("txt1");
  String name = request.getParameter("fld1");
          FileWriter fw = new FileWriter(new File(application.getRealPath("Sample.txt")), true);
                fw.write("\n"+name + ": ("+date +") : " + text + "\r\n\n");
      } catch (IOException ioe) {}


<title>::: Comments Page :::</title>
<center><form name="frmx">
<font face="arial" size="3" color="black">
<b>Please enter your name and add comments!</b></font>

<b>Name : </b><input type=field name="fld1" cols="30"/><br/><br><br>
<b>Enter Comments here:</b><br>
<textarea name="txt1" cols="100%" rows="4"/></textarea><br/>
<b>Previous Comments :</b><br/>
<textarea readonly name="txt2" cols="100%" rows="15">
<jsp:include page="Sample.txt"/></textarea><br/><br/>
<input type="submit" name="cmdbtn1" value="Add Comments"/>
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You made no point of it, but this is, is it not.

Your code appears to be stating that if the input fields are not empty, then write a new record, which implies that on page refresh the fields are not empty.

Do you have "enableviewstate" set to true, this would cause the fields to maintain their values across the refresh, so then the fields are not empty after the refresh and a new record is written.
cool_babaAuthor Commented:
I am using JSP.
 To see how this program works please follow this URL

now if you add comments once and then press the browsers refresh button, it will make another entry in the previous comments text area. i.e. it resends data to server. I dont want this to happen. I need  a solid solution so that it works on every computer and browser.

thanks for your time.
Sorry I could not get your link to work, but maybe some of the suggestions in this post will help.

Perhaps setting no cache will drop the cache on a refresh, and prevent your problem
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

cool_babaAuthor Commented:
nope it doesn't work.
Your solution is actually very simple, when the user clicks the submit button, send them to a different page to process the request, instead of posting the page to itself, which causes the page to reprocess.

Sorry if I have confused you, I will give you an example

you start from File1.htm (this is a simple html form page, there is no jsp processing on this page.) Clicking submit on this page, causes the user to be directed to File2.jsp (this page contains your jsp processing code)

So if the user clicks refresh on File1.htm, they are not processing your jsp.

Here is a reference

to send the user to file2 when the button is clicked you set the target using the "action" property of your form tag

cool_babaAuthor Commented:
Good idea..
 but what if i want to allow user to add comments more than once.. I mean the benefit of having one file is that it will allow user to add multiple comments using same site. If we have two files then user wont be able to add more comments once he/she will move to the JSP page.
 I appreciate your efforts.

Once the file2 (jsp processing file) has added the entry, redirect the user back to file1.htm

        String redirectURL = "";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cool_babaAuthor Commented:
your solution will cause an additional problem which is how to read from file using html in "file1.htm".
 I have read number of related questions on EE and i think there is no way to overcome this problem.. however i can try POST in order to give user a warning about data resubmission to the webserver.

Anyways thanks for your help and i believe you deserve points as your ideas were great..

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.