I’m writing a filter for Apache Tomcat, I was wondering if there’s a way to fetch the mimetypes placed in the /conf/web.xml file configuration file without reading the xml file explicitly. Is there anything available in the Apache Tomcat libraries perhaps?
Share
From the
tomcat/conf/web.xml:So they are available through the ServletContext.getMimeType method:
I haven’t found any other public API for getting the whole MIME type mapping. If you really need
it you can get the complete list of the extensions with this ugly hack:
It works on Tomcat 7.0.21. Since it uses Tomcat’s internal classes there is no guarantee that it will work with other Tomcat versions.
Note that you still need to call the
ServletContext.getMimeTypeto get the MIME types.The required maven dependency: