PDF file is opening in same window, but I want to open it as a seperate file
PDF file is opening in same window, but I want to open it as a seperate file without Save As dialog box.
Here is a relevant piece of servlet code:
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
res开发者_高级运维ponse.setHeader("Content-Disposition", "attachment;filename=_blank_");
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
Any suggestions?
You have two possibilities:
Content-Disposition: attachment;filename=foo.pdf
Content-Disposition: inline;filename=foo.pdf
The first prompts the user for saving the file and the dialog is browser dependent, you cannot do much about it from a server side script. The second opens the pdf inside the browser if there's a registered program capable of doing this like Adobe Reader.
You ask this question long back , may be till now you got ans of your question. I was facing same issue and my requirement was to open PDF file in separate window. Whatever suggestion given in response is good . I want to add few more lines.
In servlet you shoud add below code
webAppAccess.getHttpServletResponse().setHeader("Content-Disposition", "inline;filename=printReport.pdf");
and in jsp file
**window.open('PrintReportConsumer?operation=getShortReport&customerNumber=400000852&relationNumber=400000852&fromDate=29-Jun-2012&toDate=02-Jul-2012&languageId=en&language=en');**
精彩评论