ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Two Servlet Filters Every Web Application Should Have
Subject:   MIME types and Servlets that generate binary data
Date:   2003-12-11 22:50:25
From:   jfalkner
Response to: MIME types and Servlets that generate binary data

The filter should work fine for binary content. To set the MIME type of a response the filter relies on the ServletContext.getMimeType() method. Make sure the MIME type for your particular URL is appropriately set in either web.xml for your web app, or for your container.


For example. If I want to cache JPEG images, I could map the filter as follows.


<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.jpg</url-pattern>
</filter-mapping>


And make sure the MIME type "image/jpeg" was set for the "jpg" extension.


<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>


You would apply the same method for other MIME types and extensions.


1 to 1 of 1
  1. MIME types and Servlets that generate binary data
    2003-12-12 13:29:00  anonymous2 [View]

    • MIME types and Servlets that generate binary data
      2003-12-12 15:07:35  jfalkner [View]

      • MIME types and Servlets that generate binary data
        2003-12-15 09:02:11  anonymous2 [View]

        • MIME types and Servlets that generate binary data
          2004-01-07 18:52:12  jfalkner [View]

    • MIME types and Servlets that generate binary data
      2003-12-12 13:40:31  anonymous2 [View]

      • MIME types and Servlets that generate binary data
        2003-12-12 14:58:19  jfalkner [View]

        • MIME types and Servlets that generate binary data
          2004-01-26 21:45:24  jleech [View]

1 to 1 of 1