Java EE, accent in url, request.getParameter wrong

2019-07-16 04:25发布

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?

1条回答
在下西门庆
2楼-- · 2019-07-16 05:16

getParameter() returns decoded value, so you don't need to call decode().

Configurtation of encoding used by getParameter() depends on your servlet container. For example, in Tomcat it can be configured using URIEncoding attribute.

查看更多
登录 后发表回答