title: Flushing output stream is ignored in a Servlet under Tomcat via AJP
body: <p>Suppose I have a Java Servlet that takes a while to finish computing it's response, but I'd like the client to see intermediate response rather than wait for it to finish. For example, suppose I have the following doGet code:</p>
  
  <pre class="lang-java prettyprint-override"><code>protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
  {
      resp.setContentType("text/html");
      PrintWriter out = new PrintWriter(resp.getOutputStream());
  
      out.println("&lt;h1&gt;The Title&lt;/h1&gt;");
      out.flush();
  
      // ... some computation that takes a while
  
      // ... now print the result via out
  
      out.close();
  }
  </code></pre>
  
  <p>When I am running Tomcat locally, and accessing the Servlet, I can see the <code>&lt;h1&gt;</code> <strong>before</strong> the entire computation is completed.</p>
  
  <p>However, when I run it on my server, and access it via Apache, I only get the response <strong>after</strong> the entire request is completed (in other words, I get a blank screen instead of the <code>&lt;h1&gt;</code> which I expect to receive).</p>
  
  <p>I suspect that the issue is somewhere in AJP or Apache, seems like it's ignoring the calls to <code>flush()</code>, but I can't seem to find where the problem is.</p>
  
  <p>On the server I'm using Tomcat 6, Apache 2.2.21 and AJP 1.3</p>