title: write the file and download the file same as of attachments
body: <p>i have a requirement where i get byte array (byte[]) data from database, i need to save this data in a file and allow the user to save where ever he want to save, same as downloading the attachments.The file name and extension also i'm retrieving from database. I'm using java,spring-mvc for this.
  Below is the code:</p>
  
  <p>spring controller:</p>
  
  <pre><code>  @RequestMapping(value="/getFile", method = RequestMethod.GET)
          public ModelAndView getFile(HttpServletRequest request, HttpServletResponse response) {
  
               ModelAndView mav = new ModelAndView();
               //logic to get the data from database
  
             byte[] documentData =  document.getDOCUMENTData();
  
                 String documentName =  document.getDOCUMENTTITLE();
  
          String documentExt = document.getDocumentExtension();
  
  }
  </code></pre>
  
  <p>Please suggest, i know that using java.io.*, i can write the byte[] data in file and give file name and extension by taking the values declared above, but how can i allow users when clicked on "download file" icon to write the data and save that file where ever he wants same as downloading the attachment.Please suggest. Once user clicks on download file icon control comes to above controller.Thanks.      </p>
  
  <p>--EDIT--
   Modified code:</p>
  
  <pre><code>@RequestMapping(value="/getFile", method = RequestMethod.GET)
          public ModelAndView getFile(HttpServletRequest request, HttpServletResponse response) {
  
               ModelAndView mav = new ModelAndView();
               //logic to get the data from database
  
             byte[] documentData =  document.getDOCUMENTData();
  
                 String documentName =  document.getDOCUMENTTITLE();
  
          String documentExt = document.getDocumentExtension();
      response.setHeader("Content-Disposition", "attachment;filename="+userDoc.getDOCUMENT_TITLE());  
          long l =  userDoc.getDOCUMENT_SIZE();
          int size = (int)l;
          response.setContentLength(size);  
         response.getWriter().write("hello");//i need to write byte[] but for test i kept string.
  
  }
  </code></pre>
  
  <p>I want user to see save window so that he can save where ever he want same as downloading the attachments from mail.Thanks.</p>