如何在Tomcat 6中为任何文件扩展名设置默认的mime-tipe?

Mime类型在Tomcat的conf / web.xml文件中指定。看起来像这样:

<mime-mapping>

<extension>txt</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>

以前,我尝试以下操作:

<mime-mapping>

<extension>*</extension>

<mime-type>application/octet-stream</mime-type>

</mime-mapping>

但这对我没有帮助。如何为任何文件扩展名指定默认的mime类型?

回答:

不可能。您需要自己明确设置它们。servlet过滤器是适合此的地方。

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

response.setContentType("application/octet-stream");

chain.doFilter(request, response);

}

但是,我高度质疑企业对此的需求。这对于SEO和客户来说都是不利的。如果您的唯一目的是弹出“ 另存为”

对话框,则应这样说。有比实现错误的mime类型更好的解决方案。

以上是 如何在Tomcat 6中为任何文件扩展名设置默认的mime-tipe? 的全部内容, 来源链接: utcz.com/qa/407901.html

回到顶部