Tomcat提供错误的内容类型"text/html";用于.svg资源 [英] Tomcat serving wrong content type "text/html" for .svg resource

查看:424
本文介绍了Tomcat提供错误的内容类型"text/html";用于.svg资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用

<mime-mapping>
    <extension>svg</extension>
    <mime-type>image/svg+xml</mime-type>
</mime-mapping>

但是当我获取资源时,响应头中的内容类型设置为"text/html".是否有任何可能导致此行为的冲突因素?

but when I fetch the resource, the content type in the response header is set to "text/html". Are there any conflicting factors that may be causing this behavior?

推荐答案

ServletContext具有方法String getMimeType(String file),该方法提供文件扩展名和mime类型字符串之间的映射.

ServletContext has a method String getMimeType(String file) which provides a mapping between a file extension and a mime type string.

您可以在服务器配置中(例如在Tomcats conf/web.xml中)或在Web应用程序部署描述符中配置此映射.

You can configure this mapping in the server configuration (e.g. in Tomcats conf/web.xml) or in the web application deployment descriptor.

用于提供静态内容的servlet容器的默认servlet使用此映射来设置响应的内容类型(从提供的资源的文件名派生).

The default servlet of the servlet container which is used to serve static content uses this mapping to set the content-type of a response (derived from the filename of the served resource).

现在,如果有一个应用程序servlet生成响应,则servlet 自身负责设置内容类型.

Now if there is an application servlet which generates the response, the servlet itself is responsible to set the content-type.

这篇关于Tomcat提供错误的内容类型"text/html";用于.svg资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆