title: Download a file from JSP
body: <p>I'm trying to download a file from JSP, but to no avail.
  I created a button that calls a method in my controller</p>
  
  <pre><code>@RequestMapping(value = "scaricaFile", method = RequestMethod.POST)
  public void getScaricaFile(HttpServletRequest request, HttpServletResponse response) {
  
      String nome_file = request.getParameter("nome_file");
  
      UploadAndDownload downloadFile = new UploadAndDownload();
  
      downloadFile.download(nome_file, response);
  }
  </code></pre>
  
  <p>the download function is</p>
  
  <pre><code>public void download(String allegato, HttpServletResponse response){
  
      try {
              File file = new File(path + allegato);
              response.setContentType("application/download");
              response.addHeader("Content-Disposition", "attachment; filename=" + file.getName());
              response.setContentLength((int) file.length());
              FileInputStream input = new FileInputStream(file);
              BufferedInputStream buf = new BufferedInputStream(input);
              FileCopyUtils.copy(buf, response.getOutputStream());
      } catch (IOException e) {
          System.out.println("Errore nel download del file!");
          e.printStackTrace();
      } 
  }
  </code></pre>
  
  <p>But on my chrome page the download does not open. Why?</p>