Methods for garbled get requests in java: 1. Use [decode("variable", "UTF-8")] in [java.net.URLDecoder] to decode; solve 2. Use [java.net. [encode("Chinese", "UTF-8"] in URLEncoder] transcoding.
How to get garbled request in java:
java To pass garbled Chinese parameters in GET mode, you need to use the decode(" variable in the two classes java.net.URLDecoder
and java.net.URLEncoder
","UTF-8") and encode("Chinese","UTF-8"), the first one is decoding and the other one is transcoding.
Note: When transcoding, you need to convert two times, decoding only needs one time to solve the problem of garbled Chinese parameters. When the URL passes the parameters, the server will automatically decode it once, and then we will decode it again after we get the parameters, so the transcoding needs to be done twice.
Backend:
URLDecoder.decode(query.getName(), "UTF-8");
Front-end:
URLEncoder.encode(URLEncoder.encode("告警类型", "UTF-8"), "UTF-8");
Related learning recommendations: java basic tutorial
The above is the detailed content of What to do if the get request in Java is garbled. For more information, please follow other related articles on the PHP Chinese website!