If the URL's query string contains Chinese characters, the Request.getparameter method does not get the correct information without special handling, due to the following two mechanisms
- The browser automatically encodes the special characters in the URL, such as requesting a localhost:8080/testjsp/loginmiddle.jsp?name= test, and the URL that is actually requested is localhost:8080/testjsp/ loginmiddle.jsp?name=%e6%b5%8b%e8%af%95, where the browser automatically makes a URL encoding based on UTF-8 (page-based encoding settings) for the Chinese language
- When Web server (Tomcat) receives the link, it will decode the URL, removing "%" and decoding by default by ISO8859-1 encoding
There are two ways to get the right information
- Change the tomcat configuration so that it decodes the special characters of the URL by default by UTF-8
<port= "8080" protocol= "http/1.1" connectiontimeout = "20000" redirectport= "8443" uriencoding= "UTF-8" />
- Do the following when you get information
String text = new String (Request.getparameter ("name"). GetBytes ("Iso8859-1"), "UTF-8");
URL query string Chinese character problem