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

发布于 2024-07-19 00:28:36 字数 691 浏览 9 评论 0 原文

我正在使用 Railo 3.0 作为 Web 应用程序(设置与 这个优秀指南)。 我有一个 CFM 页面,它使用 cfcontent 标签提供一些旧的 HTML 文件。 该内容采用各种字符集(全部定义为 HTML 中的元标记)。 问题是我的所有 CFM 页面都是通过 HTTP 响应标头中设置的 UTF-8 发送的,这会覆盖 HTML 中定义的任何内容。 因此,页面在浏览器中显示不正确。

如何停止在 CFM 页面的 HTTP 标头中发送字符集?

注意: 我已从默认 Apache 配置中删除了 AddDefaultCharset 条目,这意味着现在提供的静态 HTML 页面在标头中没有任何字符集,但这对 CFM 页面没有帮助 - AddDefaultCharset 不好,不好,不好

I am using Railo 3.0 for a web application (setup exactly the same as this excellent guide). I have a CFM page that serves up some old HTML files using the cfcontent tag. This content is in various character sets (all defined as meta tags in the HTML). 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. The pages therefore get displayed incorrectly in the browser.

How can I stop the charset being sent in the HTTP headers for CFM pages?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云不回头 2024-07-26 00:28:36

我知道这是一个旧线程,但我最近遇到了类似的问题,并使用底层 java servlet 上下文克服了它。 如果你获得了 ServletResponse,你可以调用 .reset(),根据 Java 文档,它是这样的:

清除缓冲区中存在的所有数据以及状态代码和标头

您需要从头开始重写所有标头,但这会清除恶意字符集标头。

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

这在 Railo 中有效。 在 CF (Adobe) 中,我认为您需要调用 getResponse() 两次才能获取适当的响应对象。

希望对某人有帮助。

I know this is an old thread, but I have had a similar issue recently and overcame it using the underlying java servlet context. If you get hold of the ServletResponse you can call .reset(), which according to the Java docs says:

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. In CF (Adobe) I think you need to call getResponse() twice to get hold of the appropriate response object.

Hope that helps someone.

醉生梦死 2024-07-26 00:28:36

您想将页面发送为什么字符集? 您可以通过多种方式强制页面的字符集:

<cfprocessingdirective pageEncoding="windows-1252">

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?内容=Tags_g-h_07.html#3989067

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文