title: Java PrintWriter not flushing
body: <pre><code>response.setContentType("text/html; charset=UTF-8");
  PrintWriter out = response.getWriter();
  
  out.println("&lt;script language=\"JavaScript\"&gt;");
  out.println("alert('Error');");
  out.println("&lt;/script&gt;");
  
  out.println(sb);
  out.flush();
  out.close();
  </code></pre>
  
  <p>We are implementing a function to output an alert when an error is found in fliter by submitting (button) in one form (A).</p>
  
  <p>But strangely, the results of doing document.form.submit () and button.click () are different.</p>
  
  <p>If you do document.form.submit, the alert will print normally, but if you click () on the button, no alert will appear.</p>
  
  <p>Why is that?</p>
  
  <pre><code>&lt;form&gt;
     &lt;input id="btn" type = "submit" style = "display:none"&gt;
  &lt;/form&gt;
  
  
  &lt;script&gt;
    document.getElementById('btn').click();
  &lt;/script&gt;
  </code></pre>