Florian Ajir
Florian Ajir

Reputation: 4414

Java EE, accent in url, request.getParameter wrong value

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?

Upvotes: 2

Views: 3777

Answers (1)

axtavt
axtavt

Reputation: 242686

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.

Upvotes: 4

Related Questions