Solve the Java page URL address transfer parameter garbled code method

  • 2020-04-01 04:12:33
  • OfStack

The following is for everyone to share the URL address transfer parameter garbled code solution:

1. Configuration in tomcat: find server. XML under conf under the tomcat installation directory, find the following code segment, modify URIEncoding to GBK;


<Connector port="8080" protocol="HTTP/1.1"
  
connectionTimeout="20000" redirectPort="8443" URIEncoding="GBK" />

2. Implemented in Java:


String username = request.getParameter("userName");
  
try {
   
  username = new String(username.getBytes("iso-8859-1"), "GBK");
   
} 
catch (UnsupportedEncodingException e1) {
   
  e1.printStackTrace();
   
}

Before this site is to rely on this method to solve the problem of Java address parameter garbled code, I hope this article can also help you.


Related articles: