防止 Tomcat 将字符集附加到二进制内容类型

编程入门 行业动态 更新时间:2024-10-28 12:22:36
本文介绍了防止 Tomcat 将字符集附加到二进制内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个基于 Restlet 的服务,它返回以下响应:

We have a Restlet based service that returns the following response:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1, Restlet-Framework/2.0.7 X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0 Content-Disposition: inline; filename=Time_for_a_breather.pdf Date: Fri, 13 May 2011 23:41:24 GMT Accept-Ranges: bytes Content-Type: application/pdf;charset=UTF-8 Content-Length: 218495

但不幸的是,在某些浏览器(尤其是 Chrome)中,我们在查看 pdf 时遇到问题.

but unfortunately within some browsers (Chrome in particular) we are having problems viewing the pdf.

从实验和研究来看,问题似乎与 jBoss/Tomcat 将 charset=UTF-8 附加到内容类型有关,这导致浏览器感觉到它接收的文本数据不是二进制数据.

From experimenation and research it appears the problem is related to jBoss/Tomcat appending charset=UTF-8 to the Content Type which causes the browser to sense that its receiving text data not binary data.

有没有人知道防止 jBoss/Tomcat 将字符集附加到二进制数据的内容类型的方法?

Does anybody know of a way from preventing jBoss/Tomcat appending the charset to the content type for binary data?

推荐答案

就我而言,结果是 Spring 的 CharacterEncodingFilter.如果您将 forceEncoding 设置为 true,它会将字符编码添加到内容类型中,即使它对于二进制数据没有意义.

In my case, it turned out to be Spring's CharacterEncodingFilter. If you set forceEncoding to true, it will add the character encoding to the content type, even if it makes no sense as for binary data.

为了修复它,请将 forceEncoding 设置为 false 或保留默认设置.并验证它的效果,例如JSON 响应.

In order to fix it, set the forceEncoding to false or leave it in the default setting. And verify the effect it has, e.g. on JSON responses.

更多推荐

防止 Tomcat 将字符集附加到二进制内容类型

本文发布于:2023-11-03 07:59:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符集   类型   内容   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!