JSF表格和德国Umlauts [英] JSF Form and German Umlauts
问题描述
我的一个JSF(即facelet)遇到了一个奇怪的问题.我正在使用Richfaces,并且在一页上我有一个正常表单
I'm facing a strange problem in one of my JSF (which is a facelet). I'm using Richfaces and on one page I got a normal form
<h:form></h:form>
我的问题是,当我提交表单时,所有UTF-8字符(例如德国变音符(äöü))都被加密了.如果我在浏览器上将页面更改为ISO-8859-1,那么它将起作用.
My problem is when I submit the form all UTF-8 chars - like german umlauts (äöü) - are recieved encrypted. If I change the page to ISO-8859-1 on my browser it works.
如果我使用属性扩展表单
If I expand the form with attribute
<h:form id="register-form" acceptcharset="ISO-8859-1">
它也可以工作. (仅适用于德语变音符号)-其他UTF-8字符将被加密为不可读的内容.
it works too. (just for german umlauts) - other UTF-8 chars will be encrypted to something unreadable.
有人可以帮我吗?
推荐答案
You need to set the POST
request encoding by HttpServletRequest#setCharacterEncoding()
. Best place for this is a Filter
which is mapped on the desired url-pattern
. To get world domination you of course want to use UTF-8
all the time. The doFilter()
method would basically look like:
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
chain.doFilter(request, response);
然而,这并不是您唯一需要考虑的字符编码.有关Java EE Web应用程序的更多背景信息和其他(详细)解决方案,您可能还会发现本文很有用:
This is however not the only which you need to take into account with regard to character encoding. For more background information and another (detailed) solutions for a Java EE webapplication, you may find this article useful as well: Unicode - How to get the characters right?
更新:根据评论:
我已经实现了一个过滤器-稍等一下google.但这对我的问题没有影响.
然后问题出在更多用于存储/显示字符的工具中.您是如何发现这些字符乱码的?在记录语句中?如果是这样,是否使用UTF-8?还是在日志文件查看器/控制台中?如果是这样,是否使用UTF-8?还是在数据库表中?如果是这样,是否使用UTF-8?还是在数据库管理工具中?如果是这样,是否使用UTF-8?还是在结果页面中?如果是这样,是否使用UTF-8? Etcetera ..通过上述链接的解决方案部分,如何使它们正常运行.
Then the problem is more in the tool which you use to store/display the characters. How did you found out that the characters were garbled? In the logging statements? If so, does it use UTF-8? Or is it in the log file viewer/console? If so, does it use UTF-8? Or is it in the database table? If so, does it use UTF-8? Or is it in the database admin tool? If so, does it use UTF-8? Or is it in the result page? If so, does it use UTF-8? Etcetera.. Go through the solutions section of the aforementioned link how to get them all right.
这篇关于JSF表格和德国Umlauts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!