title: POI - save exported file to a client
body: <p>I'm exporting dataTable (binding dataList) to excel file calling the following method by <code>xlsWorkBookPrepare("c:\\export.xls");</code></p>
  
  <p><strong>Part of method:</strong></p>
  
  <pre><code>public void xlsWorkBookPrepare(String file) throws IOException
  {
    /* prepare of workbook */
    Workbook wb = new HSSFWorkbook();
    Map&lt;String, CellStyle&gt; styles = Style.createStyles(wb);
    ... 
  
    for (FoodList item : dataList)
    { 
      ...
    }  
  
    /* create file */
    FileOutputStream fileOut;
    try 
    {
      fileOut = new FileOutputStream(file);
      wb.write(fileOut);
      fileOut.flush();
      fileOut.close();
    } 
    catch (FileNotFoundException e) 
    {
      e.printStackTrace();
    }  
  }
  </code></pre>
  
  <p>But the path is related to the server. How to save it on side of client??</p>
  
  <p><strong>SOLUTION</strong> (based on Rangi Lin answer):</p>
  
  <pre><code>HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
  res.setContentType("application/vnd.ms-excel");  
  res.setHeader("Content-disposition",  "attachment; filename=test.xls"); 
  
  try 
  {
    ServletOutputStream fileOut = res.getOutputStream();
    wb.write(fileOut);
    fileOut.flush();
    fileOut.close();
  } 
  catch (FileNotFoundException e) 
  {
    e.printStackTrace();
  }  
  FacesContext faces = FacesContext.getCurrentInstance();  
  faces.responseComplete(); 
  </code></pre>