[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

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.io.*"%>
  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"/>
  • 4
  • 4
1 Solution
You made no point of it, but this is asp.net, 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 = "http://yoururl.com/file1.htm";
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..


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now