Servlet garbled characters, servlet Chinese garbled characters
Garbled Post: request. setCharacterEncoding ("UTF-8 ");
GET method:
1. Modify the tomcat decoding Character Set conf/server. xml URIEndoing = "UTF-8"
2. Manually recode
Username = URLEncoder. encode (username, "ISO-8859-1 ");
Username = URLDecoder. decode (username, "UTF-8 ");
Simplified:
Username = new String (username. getBytes ("ISO-8859-1"), "UTF-8 ");
Servlet Chinese garbled characters
Can you enter Chinese characters for your ID attribute? If yes, you need to set the character encoding before receiving the parameter, request. setCharacterEncoding ("gbk");, there is a response. setContentType ("text/html; charset = gbk"); in this way, do not use this sentence during development: response. setCharacterEncoding ("UTF-8 ");
Servlet Chinese garbled characters
The garbled problem is complicated, and there are many reasons! First, String name = request. getParameter ("name"); the obtained name is garbled if it is data submitted in a non-utf8 encoding method, if the encoding method specified by the page file ContentType attribute is UTF-8, the encoding method of this file must be UTF-8 or garbled. Many times we find that the encoding method of both the server and page files is UTF-8, however, it is garbled. Most of the problem is that the file encoding method is not caused by UTF-8, so you can check the page file encoding method and use EditPlus and other tools to modify the file encoding method, the encoding method specified in ContentType will tell the browser what encoding is used for parsing. If the page file is compiled by GBK, but the content type is set to UTF-8, it will be garbled!
There is a wider range of UTF-8 than GBK, said does not support Chinese broken talk!
The code above does not specifically reflect the cause of Garbled text! Garbled characters may be caused by server files, page files, and the encoding environment of servers and clients.