无法在 glassfish 3.1 中将字符集从 ISO-8859-1 更改为 UTF-8 [英] Unable to change charset from ISO-8859-1 to UTF-8 in glassfish 3.1

查看:28
本文介绍了无法在 glassfish 3.1 中将字符集从 ISO-8859-1 更改为 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 Web 应用程序响应中的字符集从 ISO-8859-1(默认)更改为 UTF-8 时遇到问题.我已经将 VM 选项 -Dfile.encoding=UTF-8 添加到 JVM 选项

I am having problems to change the charset in my web application response from ISO-8859-1 (default) to UTF-8. I already added the VM option -Dfile.encoding=UTF-8 to the JVM options

但是,我确实得到了以下 HTTP 标头作为来自 glassfish 的响应:

But still, I do get the following HTTP Header as a response from the glassfish:

Content-Type: [...;charset=ISO-8859-1]
Server: [GlassFish Server Open Source Edition 3.1]

非常感谢您的帮助/想法.

I would appreciate your help/ideas.

推荐答案

-Dfile.encoding 是关于如何读取 Java 源文件的 Oracle JVM 特定设置.这对 HTTP 响应的 Content-Type 标头中指定的字符集没有任何影响.

The -Dfile.encoding is a Oracle JVM specific setting as to how to read Java source files. This doesn't have any influence on the charset as specified in the Content-Type header of the HTTP response.

您需要将以下内容添加到您的 web.xml 中,以便将所有 JSP 的响应作为 UTF-8 发送并让它在响应标头中设置适当的字符集.

You need to add the following to your web.xml in order to send the response of all JSPs as UTF-8 and to let it set the appropriate charset in the response header.

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

另见:

  • Unicode - 如何正确获取字符?
  • 这篇关于无法在 glassfish 3.1 中将字符集从 ISO-8859-1 更改为 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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