GET Chinese garbled
// Get the name of the form submission
String name=request.getParameter("name");
name=new String(name.getBytes("ISO-8859-1"),"UTF-8");
Tomcat7 and the client to encode UTF-8 transmission data to the server, and the server request object using the ISO-8859-1 character code to receive the encoded data inconsistency, the client and server communicate therefore will produce Chinese garbled.
An array of bytes received request object ISO8859-1 character code to the original data, then the specified string by encoding constructs byte array, to solve distortion problems.
Tomcat8 GET basic versions will not be garbled because the server encoding formats can be automatically converted url
POST garbled
UTF-8 character encoding to transmit the form data to the server, the server receives also set in UTF-8 character encoding, and reception parameters must be defined before;
// set the request parameter encoding format - on GET invalid
request.setCharacterEncoding("UTF-8");
Servlet output Chinese
1 page return garbled reasons
GB2312, if the return is UTF-8 format will be displayed during garbage problem in the browser
2 How to solve content garbled
response.setContentType("text/html;charset=UTF-8");
Comprehensive set of 3
request.setCharacterEncoding ( "UTF-8"); // set request encoding
response.setCharacterEncoding ( "UTF-8"); // set the response code
response.setContentType ( "text / html; charset = utf-8"); // set the response in response to the type and content