I'm developing a simple servlet that should serve documents via http. I use URLs in the form of /getDocument?fileId=1234. The servlet simply 1) sets response.contentType and 2) writes to response.outputStream.
The problem is about setting the content type correctly in order to have the browsers understand the response (i.e., display the document using the correct application). Specifically:
a) For PDF files, if I set content type to "application/pdf", Internet Explorer understands (displays the document immediately) but Firefox does not (displays blank page without attempting to open any pdf viewer plugin). If I set it to "application/x-octetstream", Firefox understands it (displays it properly), but Internet Explorer says "unknown file type" when it asks me to save or open it.
b) Firefox understands "application/msword" and "application/vnd.ms-excel", but Internet Explorer does, strangely, not, it simple says "unknown file type".
Is it possible to get this to work consistently in all browsers, and if so, what is the correct way of setting content type for various document types? Is there anything else that should be set in the response in order for this do work correctly? Or, as I suspect, are the browsers getting confused when the URL does not end with the corresponding filename extension? (i.e., getFile?fileId=1234 instead of e.g. getFile/test.pdf)