How are HttpServletRequest parameters name (I'm asking about names not values) are encoded? So for example Heure d'arrivée
is encoded like this Heure d'arriv%C3%A9e
when I get using the method getParameterNames()
. First I though that they are encoded using URLEncoder but here the spaces are not converted. Also some other characters like "'" are not encoded.
Asked
Active
Viewed 220 times
0

Hunsu
- 3,281
- 7
- 29
- 64
-
Because [url encoding](https://www.w3schools.com/tags/ref_urlencode.asp) it is limited to the [ASCII charset](https://www.w3schools.com/charsets/ref_html_ascii.asp). `é` doesn't exist. It only remove what can't be found in it. – AxelH Aug 29 '18 at 13:08
-
Do you have a link to the documentation that says so ? Other encoder encode spaces to %20 for example. – Hunsu Aug 29 '18 at 13:10
-
You need to understand that HttpServletRequest doesn't *encode* anything. It's receiving the request, which may or may not be more or less encoded, from the decision of the HTTP client which is a completely different program and is probably not in Java. HttpServletRequest has a bunch of rules on what it will *decode* as a convenience to the caller. However, getParameterNames() is supposed to decode the names according to URL encoding rules. So it looks like you're using a J2EE container that doesn't comply to the rules. That or your request was double-encoded. – kumesana Aug 29 '18 at 13:19
-
You will find all the information about the "rules" for URI and URL in [Which characters make a URL invalid?](https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid). not a duplicate per say since you seems to ask about the method used to encode. – AxelH Aug 29 '18 at 13:22
-
As for spaces, escaping as %20 or + are both allowed in parameter values and names (and anywhere in the query string.) However, only %20 is allowed and actually means a space anywhere else in an URI. + was added as a possibility for convenience for much more user-manipulated parameters to URLs. – kumesana Aug 29 '18 at 13:23