JSF 2.0 request.getParameter返回错误编码的字符串 [英] JSF 2.0 request.getParameter return a string with wrong encoding

查看:265
本文介绍了JSF 2.0 request.getParameter返回错误编码的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF 2.0中编写一个应用程序,它支持许多语言,其中包括特殊字符。我使用String value = request.getParameter(name)和POST方法,页面编码设置为UTF-8,应用程序部署在apache tomcat 6,其连接器正确设置为utf-8在server.xml档案:

I'm writing an application in JSF 2.0 which supports many languages, among them ones with special characters. I use String value = request.getParameter("name") and POST method, the page encoding is set to UTF-8 and the app is deployed on apache tomcat 6 which has the connector set correctly to utf-8 in a server.xml file:

 <Connector URIEncoding="utf-8" connectionTimeout="20000" port="8088" protocol="HTTP/1.1" redirectPort="8443"/>

是的,我得到奇怪的结果,如Ã例如代替预期的特殊字符。我应该检查下面什么来摆脱这个问题?感谢您的帮助和建议。

Yes I get strange results like ä for example in place of expected special characters. What should I check next to get rid of the problem? Thanks for help and suggestions.

--------------编辑-------------- -----

--------------Edit-------------------

这是响应头:

Server  Apache-Coyote/1.1
Content-Type    text/html;charset=UTF-8
Content-Length  5160
Date    Sun, 10 Oct 2010 15:32:24 GMT

请求标题:

Host    localhost:8088
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729; .NET4.0E)
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language pl,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://localhost:8088/Panel/addbuilding.jsp
Cookie  JSESSIONID=DD85C95BDFEA9E51B5E4146F2643295D
Pragma  no-cache
Cache-Control   no-cache

最好的问候,
sass。

Best Regards, sass.

推荐答案

URIEncoding =utf-8只对GET请求有效。 GET包含请求网址中的参数(如浏览器地址栏中所示)。但是POST请求参数在请求正文中,而不在请求URL中。您要使用 request.setCharacterEncoding(UTF-8) 。您可以在映射到 FacesServlet 上的过滤器类中进行。

The URIEncoding="utf-8" has only effect on GET requests. GET comes with the parameters in the request URL (as you see in browser address bar). POST request parameters are however in the request body, not in the request URL. You want to use request.setCharacterEncoding("UTF-8") here. You can do it in a Filter class which is mapped on the FacesServlet.

但是,默认情况下JSF应该已经考虑到这一点,基于页面编码(如果你使用Facelets)。您确定不只是使用错误编码显示参数的stdout / logging控制台吗?

However, by default JSF should already have taken care about this based on the page encoding (if you're using Facelets). Are you sure that it isn't just the stdout/logging console which is using the wrong encoding to display the parameters?

  • Unicode - How to get characters right?

这篇关于JSF 2.0 request.getParameter返回错误编码的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆