在JSF中使用UTF-8字符读取请求参数值 [英] Reading request parameter values with UTF-8 chars in JSF
问题描述
我从包含特殊字符的GET请求读取请求参数时遇到问题.这是我的工作:
I have a problem reading request paremeters from a GET request that contain special characters. Here's what I do:
我使用javascript创建了请求网址,驱动程序名称的值是encodeURIComponent('sorumluluğumuzu') 结果是此URL,该URL在firefox中正确显示: http://localhost:8080/driver/list.xhtml ?sl = 1& drivername = sorumlulu%C4%9Fumuzu
I create the request url with javascript, and the value of drivername is encodeURIComponent('sorumluluğumuzu') The result is this URL, which shows up correctly in firefox: http://localhost:8080/driver/list.xhtml?sl=1&drivername=sorumlulu%C4%9Fumuzu
但是,当我在JSF bean中读取请求参数时: FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
However, when I read the request param in my JSF bean: FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
该值等于sorumluluÄumuzu
The value equals to sorumluluÄumuzu
我在JSF2中遇到了Tomcat7的问题,但是我们注意到Websphere6和JSF1.2上存在相同的问题.
I'm experiencing this om Tomcat7 in JSF2, but we are noticing the same issue on Websphere6 and JSF1.2.
有什么想法吗?
推荐答案
Tomcat默认情况下使用ISO-8859-1对GET请求参数进行URL解码.您需要通过Tomcat的/conf/server.xml
的<Connector>
元素中的URIEncoding
属性将其更改为UTF-8.
Tomcat by default URL-decodes GET request parameters using ISO-8859-1. You need to change it to UTF-8 by the URIEncoding
attribute in the <Connector>
element of Tomcat's /conf/server.xml
.
<Connector ... URIEncoding="UTF-8">
另请参见:
- Unicode-如何正确设置字符- JSP/Servlet请求
- Unicode - How to get the characters right? - JSP/Servlet request
See also:
这篇关于在JSF中使用UTF-8字符读取请求参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!