Java EE,URL中的重音,request.getParameter错误值 [英] Java EE, accent in url, request.getParameter wrong value
问题描述
我使用Java在Web应用程序servlet / jsp上工作,今天遇到了一个问题:
验证表单后,我将输入字段的值作为参数传递( GET
)。
我很小心地使用方法 javax.net.URLEncoder.encode(字符串, UTF-8)
,但是当此设置由重音组成时,在第二个servlet中获得的值的编码不正确。
但是我使用方法 URLDecoder.decode((String)request.getParameter( id), UTF-8 )
I work in Java on a web application servlet / jsp and I have a problem today:
After validating a form, I pass the value of an input field as a parameter (GET
).
I was careful to use the method javax.net.URLEncoder.encode (String, "UTF-8")
but when this setting is composed of accents, the encoding of the value obtained in the second servlet is incorrect.
However I use the method URLDecoder.decode ((String) request.getParameter ("id"), "UTF-8")
Ex:
id = éssai ==> http://127.0.0.1:8080/LdapJavaNet/groupe?action=consulter&id=%C3%A9ssai
print (URLDecoder.decode ((String) request.getParameter ("id"), "UTF-8")) ==> éssai
有人可以帮助我解决这个字符集问题吗?
Anyone can help me to fix this charset problem?
推荐答案
getParameter()
返回解码后的值,因此您无需调用 decode()
。
getParameter()
returns decoded value, so you don't need to call decode()
.
getParameter()
使用的编码配置取决于您的servlet容器。例如,在Tomcat中,可以使用 URIEncoding对其进行配置
属性。
Configurtation of encoding used by getParameter()
depends on your servlet container. For example, in Tomcat it can be configured using URIEncoding
attribute.
这篇关于Java EE,URL中的重音,request.getParameter错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!