title: Reload jsp page after computations
body: <p>So my project demonstrates the results of a <code>k-means</code> clustering algorithm using servlets. 
  When I cluster for the first time, everything works well and my program relocates the user to the <code>results.jsp</code> page. </p>
  
  <p>But because <code>k-means</code> is a bit random at selecting centroids, I added a <code>re-cluster</code> feature in my code in the <code>results.jsp</code> which re-clusters my data with the settings originally used.</p>
  
  <p>My servlet code for re-clustering looks like this:</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      do stuff...
      //reload results page
      String htmlResponse = "&lt;html&gt;&lt;header&gt;&lt;meta http-equiv=\"refresh\" content=\"0; URL='results.jsp\" /&gt;&lt;/header&gt;&lt;/html&gt;";
      writer.println(htmlResponse);
      //but this doesnt work...
  }
  </code></pre>
  
  <p>So after the clustering is done, I want to reload the <code>resutls.jsp</code> page. I tried adding a <code>JavaScript</code> to my <code>jsp</code> page since <code>refresh</code> is a client side operation. But the problem with that approach is that <code>refresh</code> happens before the clustering is fully completed. So I get <code>Exceptions</code> when trying to print the results. Any advice? </p>
  
  <p>My <code>refresh</code> script looks like this:     </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function refresh() {
              location.reload(true);
          }
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
              function reCluster(cluster_id) {
                  recluster();
              }
          &lt;/script&gt;
  </code></pre>
  
  <p>and on the <code>.jsp</code> i'm calling this like this:</p>
  
  <pre><code>&lt;form class="form-horizontal" action="generateArff" method="GET" enctype="multipart/form-data"&gt;
       &lt;button type="button" class="btn btn-default btn-lg" onclick="reCluster(); refresh();"&gt;
           &lt;span class="glyphicon glyphicon-refresh"&gt;&lt;/span&gt; Re-Cluster
       &lt;/button&gt;
  
       &lt;button type="submit" class="btn btn-info btn-lg"&gt;
           &lt;span class="glyphicon glyphicon-download"&gt;&lt;/span&gt; Generate file
       &lt;/button&gt;
  &lt;/form&gt;
  
  Can you advice on the matter?
  </code></pre>