【发布时间】:2012-05-17 16:44:03
【问题描述】:
在我的 grails 应用程序中,未正确编码 unicode 字符。
我正在使用 grails 1.3.7 和 tomcat 7.0.22。以下是我在我的应用中为支持 unicode 配置的设置:
- Set grails.views.gsp.encoding and grails.converters.encoding="UTF-8" in Config.groovy
- Set encoding to UTF-8 in meta tag in the .gsp pages
- Specified 'useUnicode=true&characterEncoding=UTF-8' to the MySql connection URL (DB has characterset set to UTF-8)
- Set URIEncoding="UTF-8" useBodyEncodingForURI="true" to the server.xml file in tomcat
- Specified the attribute accept-charset="UTF-8" of the form tag.
但是,当我提交一个 unicode 字符时,grails 不支持该字符并且正在保存乱码值。我已经四处搜索并阅读了 ppl 在同一问题上寻求帮助,但不幸的是,这些解决方案对我不利。虽然,我找到了解决这个问题的方法。下面的表达式
params.detail = params.detail ? new String(params.detail.getBytes("8859_1"), "UTF8") : null
将正确编码 unicode 字符。
但是,使用这种方法很乏味,因为我必须对应用程序中的所有文本输入执行此操作。为什么 unicode 字符没有被 grails 和/或 tomcat 正确编码?我认为我的设置正确。
【问题讨论】:
-
@IgorArtamonov 实际发布。
-
浏览器对页面编码的评价是什么?
-
嗯,浏览器正确编码了 unicode 字符。
-
好的,我的意思是你对
curl --head %YOURSITE%有什么要求? -
它说明了什么。喜欢
Server: Apache-Coyote/1.1Location: http://local.everest.com:9090/Transfer-Encoding: chunked