title: Java Apache POI : Writing Workbook to ServletOutputStream hangs until button clicked in client browser
body: <p>This code creates a workbook and send it to client browser. It's almost fine, response is sent back to browser and a nice popup opens up in browser asking to save, open file, or cancel the whole operation. Classic.</p>
  
  <p>The thing is, if I debug this code, <strong>sometimes</strong>, and <strong>only in IE</strong>, java machine will get stucked on line <em>wb.write(out);</em> (but I still have my excel file sent to client, I can download it and it's ok).</p>
  
  <p>Problem is I wanted to put some code after this line, so sometimes it's not executed.</p>
  
  <p>Any clue ?</p>
  
  <pre><code>public static void export(List&lt;ExportSheetData&gt; exportSheetsData, String fileName) throws IOException {
  
      FacesContext context = FacesContext.getCurrentInstance();
      HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
              .getResponse();
      response.setContentType("application/vnd.ms-excel");
      String headerResponse = "attachment;filename=";
      headerResponse = headerResponse.concat(fileName);
      response.addHeader("Content-disposition", headerResponse);
      ServletOutputStream out = response.getOutputStream();
  
      Workbook wb = new XSSFWorkbook();
      for (ExportSheetData exportSheetData : exportSheetsData) {
          Sheet sheet = wb.createSheet(exportSheetData.getTitle());
                      // creating workbook here...
      }
  
      wb.write(out); // JVM sometimes get stucked here
      out.flush();
      out.close();
      context.responseComplete();
  
  }
  </code></pre>