Hello. I'm trying to send a PDF from a servlet and was able to successfully do it, and PDF loads within the IE window. As an experiment I try to GZIP compress the PDF before I send it. The code is as follows:
The difference here is that now IE is opening a "File Download" dialog box, to save the pdf and select a viewer for the file. I was expecting that given IE is able to decompress gzip, it would first decompress the result and since I've set the content type as "application/pdf", it would open the decompressed stream in the same IE window, like the original uncompressed version of the program. Is my assumption incorrect? or is there something that I missed in order to expect the original load behavior? Thanks in advance. [ July 22, 2003: Message edited by: Philip Hung ]
You can force the browser to open the save as dialog box by setting a header to attachment. However, you can't force the browser to open the file directly. You can only suggest it. If you suggest the browser open the file, either directly or by default (as you are doing), the browser sees if it recognizes the file type. If it recognizes the file type, it looks to see whether the default in the browser settings is open or save. If it doesn't recognize the file type, it can only save. This is a good thing. I wouldn't want the browser automatically opening zip files potentially ontaining malicious attachments. Also, your content type should match what you are sending over the network. In your case that would be the zip file.
That make sense. Thanks for clarifying Jeanne. However, I'm basically using the example code in the "Core Servlet" book. There was a section regarding sending compressed pages from a servlet. So basically what I did was replace the setContentType from ("text/html") to ("application/pdf") and push a PDF info to the output stream instead of HTML. IE was able to open the "decompressed" HTML without any dialog box coming out. But I guess it was because IE naturally understands HTML, rather than PDF which required a plug-in.