Context : Apache before a Weblogic application Server.
A person can download a Pdf through our J2EE application. With Weblogic alone, the PDF is displayed properly within the wordpress plugin in most browsers.
However with Apache, the HTTP response header has
Content-type "text/html" inside it (as possible see in Firebug for instance), that leads the internet browser to show the file inline as text.
What we should submit the HTTP header from your Java code :
Content-Disposition -> title from the PDF, and
No Content-type is placed (to simplify, let us say we don't know the kind of the file within our application), which is difficult for all of us to alter that.
It appears that Apache overrides might sets its very own
Content-type, how come ?
We attempted to create
DefaultType none within the
httpd.conf but without effect.
Obviously, this is actually the same for those file types, PDF is just a good example.
Any idea ?
The reason why you create discover the filetype and fill this content-type. Every other way could be non-standard and can provide you with problems based on browser.
The filetypes can be established using
InputStream is = new BufferedInputStream(new FileInputStream(file)); mimeType = URLConnection.guessContentTypeFromStream(is);
String fileName = "/path/to/file"; MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); // only by file name String mimeType = mimeTypesMap.getContentType(fileName); // or by actual File instance File file = new File(fileName); mimeType = mimeTypesMap.getContentType(file);
Performs this help?