Home > Java > javaTutorial > body text

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

coldplay.xixi
Release: 2020-07-07 17:16:36
Original
3343 people have browsed it

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

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

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

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!

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