tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Brown" <bro...@reflexe.fr>
Subject Mapping filename extensions to MIME types automatically
Date Mon, 23 Sep 2002 07:53:02 GMT

Hello,

I have a webapp that sometimes lets a user copy a web page from a remote
site into a local directory on the server where my webapp runs (it's for a
large global intranet).

In some cases, the pages downloaded may be named ".html", ".pdf", or
whatever, so it's easy to serve up the downloaded copies later on, as the
servlet that fetches these files off the local disk can use the
"getMimeType" method of the ServletContext.  However, when I download a
document from a page such as a JSP, PHP, or ASP script, although I know the
document's MIME type, I don't *automatically* know the appropriate filename
extension, so for example, I've know way of knowing that if "script.jsp"
sends me an Adobe Acrobat document (with the appropriate MIME type) that I
should save it as "PDF".

At present, I have two options:

* hard-code the mappings between MIME types and filename extensions

* create a mapping for each file, where the MIME type is stored in some sort
of index on disk alongside the file

I've chosen the first option at present, because the second option is very
difficult to backup reliably given our network configuration.

What I'd like to do is just read the <mime-mapping> elements in web.xml, so
that I can read in such mappings dynamically.  This should be easy enough,
except that normally the web.xml file embedded in a webapp only contains
mappings that override the default mappings.  In tomcat for example, these
are defined in the default web.xml file, but I've no portable method of
reading this (i.e.: in other servlet containers, this information may be
defined differently and stored elsewhere.

Any ideas as to how I can access this information in a portable way?  It
seems wasteful to redefine information that's already available...

Thanks
Chris B.



--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message