I am trying to download a file using ajax and a servlet, but the maximum I get is that in succes I get the file parseado
I have this section of the servlet:
else if(type.equals("downloadDocument")){
            String file = request.getParameter("filePath");
            File f = new File(file);
            if (f.exists() && f.isFile()){
             OutputStream out = response.getOutputStream();
             FileInputStream in = new FileInputStream(f);
             byte[] buffer = new byte[4096];
             int length;
             while ((length = in.read(buffer)) > -1){
                 out.write(buffer, 0, length);
             }
             in.close();
             out.flush();
            }
And that call:
    $.ajax({
        type : "POST",
        url : "./ServletDocuWindow?downloadDocument",
        data : datos,
        success : function(r) {
        }
    });
 
    