开发者

JSF chars get double UTF-8 encoded

last week I asked a question but JSF and charset encoding

relevant SO question

Now I included this JSF in my JBoss Portal env. wi开发者_如何学Cth the common jboss portlet bridge. 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

äöü

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. 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).

This means that somewhere in your webapp ISO-8859-1 was incorrectly been used instead of 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). 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. To exclude the webbrowser from being suspect, then you can in e.g. Firefox determine the encoding used by View > Character Encoding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜