When the client accesses the server's page, fill in the relevant information and submit
———— 1 ———— "
The information is encapsulated in the request object and is encapsulated with the encoding format of the page setup, which we generally set to UTF-8
set page encoding format
1. Set HTML page encoding format to UTF-8
<meta http-equiv= "Content-type" content= "text/html; charset=utf-8" />
2. Set HTML page encoding format to Chinese
<meta http-equiv= "content-language" content= "ZH-CN"/>
3. Set the JSP page encoding format to UTF-8
<%@ page contenttype= "Text/html;charset=utf-8"%>
———— 2 ———— "
the server then resolves the relevant information, the default encoding format is ISO8859, so there will be garbled
As you can see, the information in the server parsing request object is encoded in a format inconsistent with the previous encoding format, so we just set up the encoding format for the server to parse the request object as well as UTF-8.
request.setcharacterencoding ("UTF-8");
It is important to note that:
This method is valid only for garbled characters in the POST request mode.
that for the get way garbled problem, we need to "server in the Request object parsing garbled" and then encoded :
1, the server is not to ISO8859 to parse, if:
String username = request.getparameter ("username");
In this case, the data stored in username corresponds to the ISO 8859 information in a coded library
2, we first find username in this code library The corresponding information:
username.getbytes ("iso8859-1");
3, and then the UTF-8 encoding format to re-parse it:
username = new String (username.getbytes ("is08859-1"), "UTF-8");
4, so at this time the username saved data is UTF-8 encoded, there will be no garbled problem
Similarly, after the hyperlink address
<a href= "/locationurl?username= China" > Hyperlinks </a>
The Chinese information should also be solved by means of the Get method.
username = new String (username.getbytes ("is08859-1"), "UTF-8");
************************************************************************************************** The following methods are best not to use, preferably using the method described above ************************************************************************************************** Other than that:
We can modify the server configuration information, to resolve garbled, regardless of the way the request, can be made, but the development process is best not to use this way.
in Tomcat, for example, we can modify the Server.xml file in the Conf directory:
<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000"
You can add related properties for Connector :
uriencoding = "UTF-8" set the encoding format for the server
for the first mention,
Request.setcharacterencoding ("UTF-8");
only valid for post, get invalid, we can add the following properties for connector:
usebodyencodingforuri= "true" enables the Get mode to also use UTF-8 encoding
HttpServletRequest Chinese Characters