Java Spring MVC在浏览器中显示PDF [英] Java Spring MVC display PDF in browser
本文介绍了Java Spring MVC在浏览器中显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制浏览器显示pdf而不下载? 这是控制器
How do I force the browser to display the pdf instead of downloading ? Here is the controller
@RequestMapping(value = "/preview.pdf", method = RequestMethod.GET)
protected String preivewSection(
HttpServletRequest request,
HttpSession httpSession,
HttpServletResponse response) {
try {
byte[] documentInBytes = getDocument();
response.setHeader("Content-Disposition", "inline; filename=\"report.pdf\"");
response.setDateHeader("Expires", -1);
response.setContentType("application/pdf");
response.setContentLength(documentInBytes.length);
response.getOutputStream().write(documentInBytes);
} catch (Exception ioe) {
} finally {
}
return null;
}
推荐答案
看起来上述控制器是服务器端所需的全部功能,问题在于浏览器不支持查看PDF文件.
It looks like the above mentioned controller is all we need from the server side, the problem is the browser doesn't support viewing PDF files.
这篇关于Java Spring MVC在浏览器中显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文