gpt4 book ai didi

java - 应用程序/pdf 数据开始下载而不是查看

转载 作者:行者123 更新时间:2023-12-01 04:36:07 25 4
gpt4 key购买 nike

我有网络应用程序。当我点击链接时:http://.....文档/ View ?type=pdf我希望浏览器显示 pdf 文件。它在 Firefox 和 IE 上工作正常,但 Chrome 开始下载它而不是显示。

代码如下:

response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=test;");
OutputStream out = response.getOutputStream();
out.write(pdfByteData);
out.flush();

可能是什么问题?可能是因为我的本地 chrome 设置或其他原因?我不知道。

最佳答案

尝试使用以下链接在 Chrome 中安装 pdf 插件

https://support.google.com/chrome/answer/142056?hl=en

How Browsers Work With File Downloads

Usually when a user goes to a file URL (for example: a download link), the file will show in the browser if the browser supports it. Image files like jpg, png, gif etc. will almost always show in the browser. Archive files like zip, tar, gzip etc. will always be downloaded. Some file types show up in some browsers but not others depending of if the browser can read the file or not. For example, Internet Explorer (IE) will usually try to show Microsoft Word files (doc and docx) in the browser, while most other browsers will download it. Google Chrome has its own PDF converter and it will try to convert a PDF file and render it in the browser.

The key thing to understand is that some browsers maybe able to read a particular file type based on the addons you have installed for that browser while others may not be able to. If a browser can read the file type it will show it in the browser. If the browser cannot read a file type it will force a download to the hard disk. Usually this is not an issue since the users can save the file to there computer after it is shown in the browser.

关于java - 应用程序/pdf 数据开始下载而不是查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17315466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com