File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

MIME Doubt

Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 121
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

Joined: Nov 27, 2007
Posts: 3
Hi mike,
Please try this,

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

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
I agree. Here's the link:
subject: MIME Doubt
It's not a secret anymore!