我正在客户端的请求中在服务器上创建一个文件。现在,我想发送该文件以响应AJAX响应。以下是JAVA代码。
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=\"Portfolio.pdf\"");
OutputStream output;
try {
output = response.getOutputStream();
output.write(Util.readFileInBytes("/Portfolio.pdf"));
output.close();
} catch (IOException e) {
e.printStackTrace();
}
现在,如何向用户显示“另存为”对话框以保存文件。在此先感谢您的帮助。
javascript代码如下:
$.ajax({
url : "export",
dataType : 'text',
contentType : 'application/pdf',
success: function() { //code to display "Save As" dialog box to user.}});
答案 0 :(得分:0)
您可以在 base64 字符串中对文件进行编码,将其发送到客户端,然后将值分配给 location.href ,并向用户显示保存对话框。
但它不适用于 IE 。不知道你的要求是什么。