views:

124

answers:

1

Mime-types are specified in Tomcat's conf/web.xml file. It's look like this:

<mime-mapping>
   <extension>txt</extension>
   <mime-type>text/plain</mime-type>
</mime-mapping>

Previously I try following:

<mime-mapping>
   <extension>*</extension>
   <mime-type>application/octet-stream</mime-type>
</mime-mapping> 

but it doesn't help me. How to specify default mime-type for any file extension?

A: 

There's no way. You need to explicitly set them yourself. A servlet filter is a suitable place for this.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
    response.setContentType("application/octet-stream");
    chain.doFilter(request, response);
}

I however highly question the business need for this. It's only disadvantageous for SEO and the client. If your sole purpose is to pop a Save As dialogue, then you should say that so. There are much better solutions to achieve this than forcing a wrong mime type.

BalusC
Thanks! Filter is that I need. I use it to set default content type "application/octet-stream". If content type is not specified, then client's app crashes due to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6806893
Ivan Kaplin