Women in Technology

Hear us Roar



Article:
  Two Servlet Filters Every Web Application Should Have
Subject:   MIME types and Servlets that generate binary data
Date:   2003-12-12 13:40:31
From:   anonymous2
Response to: MIME types and Servlets that generate binary data

Also, even if <mime-mapping> worked, it could be a problem if the content type returned by the servlet can differ. EG, imagine an image servlet which takes a GET parameter 'imageType'. Let's say, for discussion's sake, that imageType can be JPEG, GIF, SVG, PNG, etc. In this case, the URL will be distinct for different contentTypes, but <mime-mapping> cannot be used. The above-posted solution works though. I still wonder why Sun didn't include a getContentType method in their default response object.
Full Threads Oldest First

Showing messages 1 through 2 of 2.

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

    True, but a good point is that you can map your servlet to both "MyServlet.jpg" and "MyServlet.png", then use the correct URL based on if you want a JPG or a PNG -- same for other extensions and MIME types. I'd argue this is the way you should do dynamic images/content unless you really must do it a different way.
    • MIME types and Servlets that generate binary data
      2004-01-26 21:45:24  jleech [View]

      But isn't it a goal to make the filters as easy as possible to retrofit to existing applications? Sure, you could go in, add the filters, change lots of links to accomodate them, and add lines of code to web.xml to map everything -- Or just cache the response headers along with the rest of the response and everything is much simpler.
      Here's a real-world example of a situation where your suggestion wouldn't work -- and you really must do it a different way: A web form that lets the user input a bunch of parameters, including ouput format, e.g. { .pdf, .xml, .csv, .html }.
      The only compelling reason I can see to use extensions on the URLs for the content is to satisfy really old, broken versions of Internet Explorer. And you can trick them anyway by appending ?.pdf or &.pdf to the URL...