Hi Dean, I did it once, and i did like this: (solution for PDF file working on IE and any Acrobat Version) ... response.setContentType("application/octet-stream"); // Acrobat 4 seems "donīt like" 'application/pdf' byte[] data = xxx.getData(); response.setContentLength(data.length); response.setHeader("Content-Disposition","inline; filename=file.pdf"); /* extension .pdf makes IE choose Acrobat to open the document * content 'inline' avoids popping-up the Open/Save Dialog twice in older IE version ( 5.0 ) */ out = response.getOutputStream(); out.write(data); out.flush(); out.close();
Ok, iīm sure it works with Acrobat4+ and IE5+. I did not tested in Linux and other browsers. Henrique Viecili ----- Original Message ----- From: Dean A. Hoover To: [EMAIL PROTECTED] Sent: Friday, June 04, 2004 9:37 AM Subject: HTTP header for dynamic pdf and IE6 Sorry if this is inappropriate for this list, but I really don't know where else to turn. I figured someone on this list may have solved it. I have a java web application that allows an end-user in their browser to download a "file", which happens to be bytes stored in a database. In experimenting with how to do this, I have this snippet of code in my Action: AttachmentListItem attachment = EmailSQL.getAttachmentListItem(connection, 3, 1); response.setContentType(attachment.getContentType()); byte[] data = EmailSQL.getAttachmentBytes(connection, 3, 1); response.setContentLength(data.length); response.setHeader("Content-Disposition", "attachment; filename=\"" + attachment.getFileName() + "\""); ServletOutputStream out = response.getOutputStream(); out.write(data); out.flush(); out.close(); To test this out, I hit the link in my IE browser which brings up a dialog box allowing me to "Open" or "Save" the file. If I save the file, it does the right thing. If I press the open button, Acrobat Reader opens up and then errors out with an alert box: "There was an error opening the document. The file does not exist." I have a yahoo email account that I tried a test on. I sent an email message with the same pdf file attached to that account. I wanted to see if yahoo figured out how to make this work. They did! (but I can't figure out how to replicate) Their header looks like this: Date: Thu, 03 Jun 2004 15:37:58 GMT P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV" Content-Disposition: attachment; filename=reference.pdf Connection: close Transfer-Encoding: chunked Content-Type: application/pdf; filename="foo.bar" .s4g--&v=1 There is also some other stuff I am seeing just after the header: .s4g-&v=1 which looks something like a query string, but I'm not sure. My header looks like this: HTTP/1.1 200 OK Date: Thu, 03 Jun 2004 15:35:15 GMT Server: Apache/2.0.40 (Red Hat Linux) mod_perl/1.99_07-dev Perl/v5.8.0 mod_jk/1.2.5 PHP/4.2.2 mod_python/3.0.1 Python/2.2.2 mod_ssl/2.0.40 OpenSSL/0.9.7a Set-Cookie: JSESSIONID=DD3D0938B780EEBEBDC1B558CCBAD095; Path=/ Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Disposition: attachment; filename="reference.pdf" Content-Length: 214982 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: application/pdf;charset=UTF-8 Does anyone know how to work around this problem? I suppose there are actually 2 parts to this: 1) What is the magic in the HTTP header that allows this to work? 2) How can one create such a header in java? Thanks. Dean Hoover --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]