无法将字符集从ISO-8859-1更改为UTF-8在glassfish 3.1
我有问题将我的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]
您的帮助/想法。
-Dfile.encoding
Oracle JVM特定设置如何读取Java源文件。这对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 - 如何获得正确的字符?
- Unicode - How to get the characters right?