简体   繁体   English

如何停止在Railo应用程序的HTTP标头中设置字符集?

[英]How do I stop charset being set in the HTTP headers of a Railo application?

I am using Railo 3.0 for a web application (setup exactly the same as this excellent guide). 我正在将Railo 3.0用于Web应用程序(设置与出色的指南完全相同)。 I have a CFM page that serves up some old HTML files using the cfcontent tag. 我有一个CFM页面,该页面使用cfcontent标记提供一些旧的HTML文件。 This content is in various character sets (all defined as meta tags in the HTML). 此内容包含各种字符集(均定义为HTML中的meta标签)。 The problem is that all my CFM pages are getting sent out with UTF-8 set in the HTTP response headers, and this overrides anything defined in the HTML. 问题是我的所有CFM页都在HTTP响应标头中设置了UTF-8的情况下发出了,这会覆盖HTML中定义的所有内容。 The pages therefore get displayed incorrectly in the browser. 因此,页面在浏览器中显示不正确。

How can I stop the charset being sent in the HTTP headers for CFM pages? 如何停止在CFM页面的HTTP标头中发送的字符集?

Notes: I've removed the AddDefaultCharset entry from the default Apache config, and this means that static HTML pages are now served without any charset in the header, however this didn't help for CFM pages - AddDefaultCharset is bad, bad, bad 注意:我已经从默认的Apache配置中删除了AddDefaultCharset条目,这意味着现在可以提供静态HTML页面,而标题中没有任何字符集,但这对CFM页面没有帮助-AddDefaultCharset不好,不好,不好

I know this is an old thread, but I have had a similar issue recently and overcame it using the underlying java servlet context. 我知道这是一个旧线程,但是最近我遇到了类似的问题,并使用基础的Java servlet上下文克服了它。 If you get hold of the ServletResponse you can call .reset(), which according to the Java docs says: 如果掌握了ServletResponse,则可以调用.reset(),根据Java文档,它会说:

Clears any data that exists in the buffer as well as the status code and headers . 清除缓冲区中存在的所有数据以及状态代码和标头

You'll need to rewrite ALL the headers from scratch, but it will clear the rogue charset header. 您需要从头开始重写所有标头,但是它将清除流氓字符集标头。

<cfset objResponse = GetPageContext().getResponse()>
<cfset objResponse.reset()>

This works in Railo. 这适用于Railo。 In CF (Adobe) I think you need to call getResponse() twice to get hold of the appropriate response object. 在CF(Adobe)中,我认为您需要调用两次getResponse()才能获得适当的响应对象。

Hope that helps someone. 希望能对某人有所帮助。

what charset are you trying to send the pages out as? 您尝试以什么字符集将页面发送出去? you can force the charset of the page a couple of ways: 您可以通过以下几种方式强制页面的字符集:

<cfprocessingdirective pageEncoding="windows-1252">

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_13.html#2962107 http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_13.html#2962107

<cfheader name="charset" value="windows-1252">

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_07.html#3989067 http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_07.html#3989067

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM