This article introduces the solution to the garbled java URL. Friends in need can refer to it
Usually we encode once and then directly accept the parameters
String para = request.getParameter(paramName); This is because the container can automatically help us decode (DECODE)
Generally speaking, when encoding, UTF-8 (system encoding) Then if UTF-8 is also used when decoding, then the legendary garbled characters will not appear~
But if UTF-8 is used in the JSP page, but the container decodes it If other encodings are used, 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 the methods. What should I do if I still can’t figure it out?
How to solve this encoding problem caused by multiple servers:
AssumeString: = "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. Okay, you can get %E9%98%B3 correctly
Then as long as you perform Decode once, you can get "Yang"
The above is the detailed content of What to do if the java URL is garbled?. For more information, please follow other related articles on the PHP Chinese website!