Working with mime-types (e.g. in your own servlet environment) is very easy, if you know the basics implemented in Java. The main object we need is the java.net.FileNameMap
. Its method #getContentTypeFor(String fileName)
returns the mime-type for the desired filename. You can get a default implementation of FileNameMap
from java.net.URLConnection#getFileNameMap()
. (Btw: There are different subclasses of URLConnection
to handle jars or URLs.)
The default mime-types are generally read from the properties file JAVA_HOME/lib/content-types.properties
. There you can find only the most important ones, not really useable in a complex servlet environment. But you can copy this properties file, adapt it to your special needs and force the URLConnection
to load it. You just have to set the system property content.types.user.table
to your own properties file.