Home >Java >javaTutorial >What should I do if the get request in Java is garbled in Chinese?
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].
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.Java Video Tutorial# ###########java.net.URLDecoder.decode(param, "utf-8");
Related learning recommendations:
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!