title: On browser refresh, java method in JSP scriptlet is getting called
body: <p>I have a requirement where on clicking a button, I have to empty the text area, which is populated from a file, and need to empty the file contents also.</p>
  
  <p>My jsp page looks like this</p>
  
  <pre><code>&lt;%@page import="com.hcentive.rule.DisplayLog"%&gt;
  &lt;%@ page import="java.lang.*" import="java.util.Scanner"  
      import="java.io.FileReader" import="java.net.*"%&gt;  
  
  &lt;%  
  DisplayLog log = new DisplayLog();  
  log.display();  
  %&gt;  
  
  &lt;html&gt;   
      &lt;body&gt;  
       &lt;script&gt;
          function validate() {
             alert("clear clicked");
             document.getElementById("rule").value = "";
             &lt;%
                  log.clear(); 
             %&gt;
          }
          &lt;/script&gt;   
        &lt;br&gt;&lt;br&gt;
          &lt;FORM&gt;
              &lt;textarea rows="20" cols="162" wrap="off" id="rule" &gt;&lt;%=log.getFileOutput()%&gt;&lt;/textarea&gt;  
              &lt;br&gt;&lt;br&gt;
              &lt;input type="button" value="Clear" onclick="validate();" &gt;
          &lt;/FORM&gt;  
      &lt;/body&gt; 
  &lt;/html&gt;  
  </code></pre>
  
  <p>In above code, <strong>DisplayLog</strong> is a java class. <strong>display</strong> method is used to read file contents and write in the text area and <strong>clear</strong> method is used to empty the file contents.  </p>
  
  <p>It is working fine when i click the clear button it empties the text area.The problem that i am facing is that on browser refresh, <code>log.clear()</code> is also getting called which i don't understand.</p>
  
  <p>Please someone help.</p>