Home >Java >javaTutorial >What should I do if the get request in Java is garbled in Chinese?

What should I do if the get request in Java is garbled in Chinese?

coldplay.xixi
coldplay.xixiOriginal
2020-07-07 09:25:283385browse

Solution to Chinese garbled code in get request in java: 1. Manual decoding, the code is [param=newString(param.getBytes("iso8859-1"), "utf-8")]; 2. Configuration tomcat, modify tomcat's [server.xml].

What should I do if the get request in Java is garbled in Chinese?

Solution to Chinese garbled characters in get request in java:

Method 1: Manual decoding

    param = new String(param.getBytes("iso8859-1"), "utf-8");

This method depends on the server

Method 2: Configure tomcat

Modify tomcat’s server.xml: URIEncoding="utf-8 "

This method depends on the server

Method three: URL encoding (does not depend on Tomcat configuration, recommended):

Two browsers URL encoding.

 var param = "中";
 param = encodeURI(param);
  alert(param);
  param = encodeURI(param);
  alert(param);

                            iousular/param_encoded twice and then passed to the background

                       

                       Construction will be passed to the background after being encoded twiceâ€â€

The server will do the URL decoding again.

When the parameters are passed to the server, the server will automatically decode the parameters. We only need to manually decode them once

 java.net.URLDecoder.decode(param, "utf-8");

Related learning recommendations:
Java Video Tutorial# ###########

The above is the detailed content of What should I do if the get request in Java is garbled in Chinese?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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