This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a webapp that can generate different file types(PDF, XLS, CSV) Once file is generated, the response is sent where browser asked to open or save file. Save works for all files(including PDF), no problem.
Open however, works for every type except PDF. When clicking open, adobe reader starts, then it displays a popup error message saying: "There was an error opening this document. This file cannot be found".
I set content type to application/pdf. Although I've tried a bunch more: application/download, application/force-download, application/octet-stream application/x-unknown, multipart/download, etc.
I set Cache-control header to rivate, no-store, no-cache, must-revalidate. Pragma = no-cache
Content-disposition is set to : "attachment;filename="someFileName.pdf"
content-length is correctly set.
To work around an Excel problem I had to add extra url mapping where a request url which ended in the filename that matched the filename passed in content-disposition would generate the same file again. This is a known workaround for how retarded windows/Office/IE works, as Excel retrieves the file itself from the web server using the filename even if the browser has retrieved the file already. This only seems to happen with attached, not inline. Inline is not an option for me however.
This "filename URL" workaround is also available to whatever other programs opens PDF files, like Adobe reader. And looking at my logging I see adobe reader sending the request to get the document with the filename as the last part of the URI. The document is generated and sent back. So in effect it is generated twice. Which his fine, if it only worked!!
On linux everything works fine, PDFs opens fine in both ghost view or acroread. Quality programs!
I've run out of ideas, anyone see what I've forgotten? Help!
Joined: Jan 29, 2004
In case someone else wonders, and just to reply to myself,
In the servlet(actually, a struts action) that generate the files, I now set the headers to: response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public");