How to set default mime-tipe for any file extension in Tomcat 6?

后端 未结 1 931
遥遥无期
遥遥无期 2020-12-11 01:50

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


   txt
   

        
相关标签:
1条回答
  • 2020-12-11 02:33

    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.

    0 讨论(0)
提交回复
热议问题