title: Don't work response Disposition attachfile xlsx file
body: <p>I am working on trying to use Apache POI to make an xlsx file.
  However, it is not working. Please help me.</p>
  <p>I want an xlsx file download but that is not working. Send url ajax and a success alert is shown, but file is not downloaded.</p>
  <p>There is no error output to the console. It just is not working.</p>
  <pre><code>private void makeExcel(List&lt;Map&lt;String, Object&gt;&gt; list, ArrayList&lt;String&gt; columnTitle,String fileName, HttpServletResponse response) {
      
      ArrayList&lt;String&gt; columnList = new ArrayList&lt;&gt;();
      if (list != null &amp;&amp; list.size() &gt; 0) {
          Map&lt;String, Object&gt; m = list.get(0);
          for (String key : m.keySet()) {
              columnList.add(key);
          }
      }
  
      //  1. Workbook
      XSSFWorkbook workbook = new XSSFWorkbook();
  
      //  2. Sheet
      XSSFSheet sheet = workbook.createSheet(&quot;sheet1&quot;);
  
      XSSFSheet sheet2 = workbook.createSheet(&quot;sheet2&quot;);
  
      //  3. Row
      XSSFRow row = null;
      
      XSSFRow row2 = null;
  
      //  4. Cell
      XSSFCell cell = null;
      
      XSSFCell cell2 = null;
      
      CellStyle headStyle = workbook.createCellStyle();
  
      headStyle.setFillForegroundColor(HSSFColorPredefined.YELLOW.getIndex());
      headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
      headStyle.setAlignment(HorizontalAlignment.CENTER);
  
      if (list != null &amp;&amp; list.size() &gt; 0) {
          int i = 0;
  
          for (Map&lt;String, Object&gt; mapObject: list) {
              row = sheet.createRow((short)i);
              if(i == 0) {
              if(columnTitle !=null &amp;&amp;columnTitle.size() &gt;0){
                  for(int j=0; j&lt;columnTitle.size(); j++) {
                      cell = row.createCell((short)j);
                      cell.setCellStyle(headStyle);
                      cell.setCellValue(String.valueOf(columnTitle.get(j)));
  
                  }
                  i++;
                  row=sheet.createRow((short)i);
                  }
              }
              if (columnList != null &amp;&amp; columnList.size() &gt; 0) {
                  for (int j = 0 ; j &lt; columnList.size() ; j ++) {
                      cell = row.createCell((short)j);
                      cell.setCellValue(String.valueOf(mapObject.get(columnList.get(j))));
                  }
              }
              i++;
          }
      }
  //  FileOutputStream fileOutputStream = null;
      try {
  //      fileName =  URLEncoder.encode(fileName,&quot;UTF-8&quot;).replaceAll(&quot;\\+&quot;,&quot;%20&quot;);
  
          response.setHeader(&quot;Content-Disposition&quot;, &quot;attachment;filename=excelFileName.xlsx&quot;);
          response.setContentType(&quot;application/vnd.ms-excel&quot;);
            
          OutputStream out = new BufferedOutputStream(response.getOutputStream());
  
          workbook.write(out);
  //      out.flush();
      
          out.close(); 
          workbook.close();
      }
      catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>