简体   繁体   English

JSF字符获得双UTF-8编码

[英]JSF chars get double UTF-8 encoded

last week I asked a question but JSF and charset encoding 上周我问了一个问题,但JSF和字符集编码

relevant SO question 相关的SO问题

Now I included this JSF in my JBoss Portal env. 现在,我将此JSF包含在我的JBoss Portal环境中。 with the common jboss portlet bridge. 与常见的jboss portlet桥。 When I submit my form something weird happens: 当我提交表格时,发生了一些奇怪的事情:

The portal is UTF-8 so my form inputs are UTF-8 too but after the submit the chars are encoded as UTF-8 again which causes something like this 门户网站是UTF-8,所以我的表单输入也是UTF-8,但是在提交之后,字符再次被编码为UTF-8,这会导致类似的情况

äöü

If the response page is submitted again it turns into this 如果响应页面再次提交,它将变成这个

äöü

You can hit the submit button and see the chars getting encoded everytime again. 您可以单击“提交”按钮,然后再次看到字符被编码。

Is this working as intended? 这按预期工作吗?

This will happen when the data which is initially decoded using UTF-8 has been incorrectly encoded using ISO-8859-1 . 当最初使用UTF-8解码的数据已使用ISO-8859-1错误编码时,会发生这种情况。 You can easily reproduce this by: 您可以通过以下方式轻松重现此内容:

String input1 = new String("äöü");
System.out.println(input1); // äöü
String input2 = new String(input1.getBytes("UTF-8"), "ISO-8859-1");
System.out.println(input2); // äöü
String input3 = new String(input2.getBytes("UTF-8"), "ISO-8859-1");
System.out.println(input3); // äöü

(note that the last one actually contains more characters, but SO's message parser ate them). (请注意,最后一个实际上包含了更多字符,但是SO的消息解析器将它们删除了)。

This means that somewhere in your webapp ISO-8859-1 was incorrectly been used instead of UTF-8 . 这意味着您的Web应用程序中的某个地方未正确使用ISO-8859-1而不是UTF-8 It's hard to pinpoint the root cause with the as far given information. 很难用现有的信息来查明根本原因。 You can try to sysout the request parameters in the JSF bean action method and read the output in stdout (you only need to ensure that the stdout is using UTF-8 as well! if you're using an IDE like Eclispe, you can configure that in Workspace preferences ). 您可以尝试在JSF bean操作方法中对请求参数进行sysout,并在stdout中读取输出(您只需确保stdout也使用UTF-8 !如果您使用的是类似Eclispe的IDE,则可以配置工作空间首选项 )。 If those chars looks garbage as well, then it's the request encoding which is wrong. 如果这些字符看起来也很垃圾,那么请求编码是错误的。 If those chars looks fine, then it's the response or webbrowser encoding which is wrong. 如果这些字符看起来不错,那么响应或Web浏览器编码是错误的。 To exclude the webbrowser from being suspect, then you can in eg Firefox determine the encoding used by View > Character Encoding . 为了排除怀疑的网络浏览器,您可以在Firefox中确定“ 视图” >“ 字符编码”所使用的编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM