打开/保存为...对话框不显示 [英] Open/Save as... dialog box not showing
问题描述
使用Spring Framework,我使用javax.servlet.http。 HttpServletResponse创建正确的响应和相应的标题:
response.setHeader(Expires,-1);
response.setHeader(Cache-Control,must-revalidate,post-check = 0,pre-check = 0);
response.setHeader(Pragma,public);
response.setContentType(application / pdf);
response.setHeader(Content-Disposition,attachment; filename =content.pdf);
response.setContentLength(content.size());
然后我使用ServletOutputStream编写内容:
ServletOutputStream os;
try {
os = response.getOutputStream();
os.write(((ByteArrayOutputStream)baos).toByteArray());
baos .close();
os.flush();
os.close();
} catch(IOException e1){
// TODO自动生成的catch块
e1.printStackTrace();
}
在客户端,我收到HTTP代码200,并接收正确的响应正文,使用PDF文件,但另存为...弹出窗口没有出现。
有什么理由可能导致此问题的Header配置或可能在其他地方?
谢谢。
当我运行这个代码的问题凸轮e在
response.setHeader(Content-Disposition,attachment; filename =content.pdf);
定义文件名
尝试: / p>
response.setHeader(Content-Disposition,attachment; filename =+content.pdf);
它将打开对话框,并在点击保存按钮时保存为选项
I have a PDF file on my server that I need the user to download from the client side.
Using Spring Framework, I use javax.servlet.http.HttpServletResponse to create the correct response and corresponding header:
response.setHeader("Expires", "-1");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename="content.pdf");
response.setContentLength(content.size());
Then I use the ServletOutputStream to write the content:
ServletOutputStream os;
try {
os = response.getOutputStream();
os.write(((ByteArrayOutputStream)baos).toByteArray());
baos.close();
os.flush();
os.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
On the client side, I receive HTTP code 200 and receive the correct response body, with the PDF file, but the 'Save As...' pop-up did not appear.
Is there any reason on the Header configuration that could lead to this problem or could it be somewhere else?
Thank you.
When I ran this code the problem came in
response.setHeader("Content-Disposition", "attachment;filename="content.pdf");
for defining filename
Try:
response.setHeader("Content-Disposition", "attachment;filename="+"content.pdf");
It will open up dialog box and will give you save as option when clicking save button
这篇关于打开/保存为...对话框不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!