Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:56:41+00:00 2026-05-26T02:56:41+00:00

I’m writing a filter for Apache Tomcat, I was wondering if there’s a way

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:56:41+00:00Added an answer on May 26, 2026 at 2:56 am

    From the tomcat/conf/web.xml:

    <!-- ======================== Introduction ============================== -->
    <!-- This document defines default values for *all* web applications      -->
    <!-- loaded into this instance of Tomcat.  As each application is         -->
    <!-- deployed, this file is processed, followed by the                    -->
    <!-- "/WEB-INF/web.xml" deployment descriptor from your own               -->
    <!-- applications.                                                        -->
    

    So they are available through the ServletContext.getMimeType method:

    @Override
    protected void doGet(final HttpServletRequest req, 
            final HttpServletResponse resp) throws ServletException, IOException {
        final ServletContext servletContext = req.getServletContext();
        final String mimeType = servletContext.getMimeType("filename.txt");
        ...
    }
    

    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:

    import java.util.Arrays;
    import java.lang.reflect.Field;
    import org.apache.catalina.connector.Request;
    import org.apache.catalina.connector.RequestFacade;
    import org.apache.catalina.core.StandardContext;
    
    ...
    
    // ugly reflection hack - do NOT use
    final RequestFacade tomcatRequestFacade = (RequestFacade) req;
    final Class<? extends RequestFacade> requestFacadeClass = 
        tomcatRequestFacade.getClass();
    try {
        final Field field = requestFacadeClass.getDeclaredField("request");
        field.setAccessible(true);
        final Request tomcatRequest = (Request) field.get(tomcatRequestFacade);
        final StandardContext standardContext = 
            (StandardContext) tomcatRequest.getContext();
        final String[] mappings = standardContext.findMimeMappings();
        logger.info("mapping list: {}", Arrays.asList(mappings));
    } catch (final Exception e) {
        logger.error("", e);
    }
    

    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.getMimeType to get the MIME types.

    The required maven dependency:

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-catalina</artifactId>
        <version>7.0.21</version>
        <scope>provided</scope>
    </dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.