Usually we encode once and then accept the parameters directly
String para = request.getParameter(paramName); This is because the container can automatically decode (DECODE) for us
Generally speaking, when encoding, UTF-8 (system encoding) is used. If UTF-8 is also used when decoding, then the legendary garbled characters will not appear~
However, if UTF-8 is used in the JSP page, but other encodings are used when decoding the container, garbled characters may appear.
At this time, you can generally use:
String param = new String(request.getParameter(paramName).getBytes("ISO-8859-1"),"UTF-8");
Can also come out.
I have tried all means. What should I do if I still can’t figure it out?
How to solve this encoding problem caused by multiple servers:
Assume string: = "Yang";
Encode once%E9%98%B3
Encode twice%2525E9%252598%2525B3
In the second time, the container automatically decodes this time, whether it is GBK, UTF-8 or ISO-8859-1, it can get %E9%98%B3 correctly.
Then as long as you perform Decode once, you can get "Yang"