aspose file tools*
The moose likes Servlets and the fly likes MIME Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "MIME Doubt" Watch "MIME Doubt" New topic
Author

MIME Doubt

Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I have an application which can uplodad any type of files with whaever formats/extensions like .doc,.zip,.ppt,.pdf,.txt... I am storing this files in the db using blob and also I can able to retrieve the fiel from db to the local disk. I have written a servlet which can read the file from the local disk. But I don't know how to set the setContentType for different extensions. Whether I have to set the contentType differently for different file types or any other way to do it.
For example:
Below code is for word document to be read:


For .ppt / .txt / .pdf, whether I have to change the contentType or some any common contentType is available for use
mani vannann
Greenhorn

Joined: Nov 27, 2007
Posts: 3
Hi mike,
Please try this,
response.setContentType("APPLICATION/OCTET-STREAM");


Thanks and Regards<br />Mani vannann.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

See ServletContext.getMimeType
which will give you access to the same mechanism that the container uses to set mime types by file extension when it serves up static files.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MIME Doubt