Home > Java > javaTutorial > body text

What to do if the get request in Java is garbled

coldplay.xixi
Release: 2020-08-21 09:57:32
Original
2939 people have browsed it

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.

What to do if the get request in Java is garbled

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");
Copy after login

Front-end:

URLEncoder.encode(URLEncoder.encode("告警类型", "UTF-8"), "UTF-8");
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template