起初,缓存并不是在所有浏览器中都有效。然后我通过向 url 添加 .pdf 扩展名使其在除 IE (IE8) 之外的所有浏览器中工作。之后 Servlet 停止被调用。
我通过加载以下 url 的 EMBED 标记在网页上内联显示 pdf 文件:
http://localhost:7001/app/viewFile.pdf
它由具有以下 header 的 java servlet 生成:
response.addHeader("Content-Disposition", "inline;");
response.setHeader("Cache-control", "cache,max-age=600");
response.setContentType(mimeType);
response.setContentLength(contentLength);
为了在所有浏览器中显示 pdf,我使用 Adobe Reader 9.2.0。
如何让它在 IE 中也能正常工作?我注意到 IE 将“Cache-Control: no-cache” header 添加到 request,而 Safari 则没有。
最佳答案
如前所述,cache-control
header 值 cache
无效。请改用 public
。
至于IE在embed
和object
元素中不遵守服务器端缓存控制规则,不幸的是这是IE的一个“特性”。您能做的最好的事情就是用 iframe
元素替换它。
其他 header ,如 expires
、last-modified
、etag
等都没有帮助。
关于java - 在 IE 中启用 pdf 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1807753/