title: Folder browsing dialog for file download in Java
body: <p>I make an ajax call to a java servlet for download a xml file on client. I use this code for append a form on "success" ajax call and I force trigger for effective start file download.</p>
  
  <p>My issue is that i would like to permit client user to choose where save the file and not download it in default browser folder.</p>
  
  <p>Can I do that?</p>
  
  <p>My client code is:</p>
  
  <pre><code>  function downloadAnnotationXML()
          {
             downloadAnnotation=true;
             var temp=new Object();
             temp.topic=topic;
             temp.operation=operation
             temp.data=annotazioniXml;
             var json = JSON.stringify(temp);
             var url="&lt;%=request.getContextPath()%&gt;/DownloadAnnotationServlet";
             $.ajax({
              type: "POST",
              url: url,
              data: {json:json},
              success: function(response, status, request) {
                  var disp = request.getResponseHeader('Content-Disposition');
                  if (disp &amp;&amp; disp.search('attachment') != -1) {
                      var form = $('&lt;form id="ajax" method="POST" action="' + url + '"&gt;');
                     form.append($('&lt;input type="hidden" name="json" value="json"&gt;'));
  
                      $('body').append(form);
                      form.submit();
                  }
              },
              error:function(jqXHR, textStatus, thrownError ) 
               {
                  error = "Non è stato possibile caricare l'oggetto";         
                  msg = textStatus + thrownError;
                  promptError(error+" &lt;br /&gt; "+ msg);         
              }
            });
          }
  </code></pre>
  
  <p>My java servlet code for header is :</p>
  
  <pre><code>   response.setContentType("application/octet-stream");
     response.setHeader("Content-Disposition", "attachment;filename="+file.getName());
  
                  OutputStream outStream = response.getOutputStream();
      byte[] buffer = new byte[4096];
      int bytesRead = -1;
      while ((bytesRead = inStream.read(buffer)) != -1) {
          outStream.write(buffer, 0, bytesRead);
      }
      inStream.close();
      outStream.close();   
  </code></pre>
  
  <p>All work well but file is downloaded on default browser folder. :(</p>