一开始,我无法使任何带有音符的字母正确显示。幸运的是,我找到了this post,通过在我的.properties文件中使用转义Unicode,我能够取得进展。
(顺便说一句,虽然转义的Unicode基本上解决了问题,但它使.properties文件难以阅读。幸运的是,IDEA提供了一个选项,可以使用转义的Unicode并仍然使用可读的字符来读取文件。在此处阅读更多信息。)
现在我的问题是:在我的应用程序的某些部分,带有变音符号的字母会显示为Latin-1 HTML实体名称。例如,我看到的是"& amp;ccedil;"(我在&和amp之间添加了一个额外的空格,否则它将呈现为和号),而不是'ç'。起初,我甚至不知道那是什么意思,但在查看this table后,我知道这是ISO-8859-1实体名称。
以下是我尝试过的方法,但没有成功地给我带来带有变音符号的字符。
Although I'm still using Glassfish 2, I found this post, and tried adding the following to my web.xml
<jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <page-encoding>UTF-8</page-encoding> </jsp-property-group> </jsp-config>
Now, when I check the response headers in Chrome dev tools, I can see the the following:
Content-Type:text/html;charset=UTF-8
However, I still see the aforementioned HTML entity names in my UI.
I tried explicitly setting the charset within the JSP itself by adding the following to the JSP where the values are pulled from the .properties file:
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
While trying to fix this, I've read that ISO 8895-1 is the default encoding for properties files, so I tried changing the encoding within IDEA (I'm using 11, btw). You can do so by going to Settings > File Encodings. At the bottom is an option entitled "Default encoding for properties file", and I changed it to UTF-8. However, I still see the HTML entity names.
我已经尝试了一段时间,现在我终于到了无可奈何的地步。有什么建议吗?