The Chinese Garbled text in Java should be a problem we often encounter. Today we will summarize the solutions to the Garbled text problem:
1. The Link contains Chinese characters. <a class = "add" href = "system/showdataadd. Action? Title = customer level & datatype = clientrank & rel = clientrankset "> Add </a>
In this way, if the data obtained in the background is not processed, Chinese characters may be garbled. Because the hyperlink actually uses the get method to transmit values, the solution to this problem is as follows:. in the conf folder of Tomcat we use
Server. XML, find <connector Port = "8080" protocol = "HTTP/1.1" connectiontimeout = "20000" redirectport = "8443"/> in the file, and add
Write uriencoding = "gb2312.
2. Use the code on the server. For example, title is a Chinese character to be processed:
public void setTitle(String title) { try { this.title = new String(title.getBytes("ISO-8859-1"), "gbk"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
3. The page sends the data to encodeuri once, and the server uses new string (old. getbytes ("iso8859-1"), "UTF-8 ")
For example, VAR url = "ajaxserver? Name = "+ encodeuri ($ (" # username "). Val (); // encodeuri handles Chinese garbled characters
4. encodeuri processing is performed for the data sent from the page, and urldecoder. Decode (old, "UTF-8") is used for the server ");
For example, VAR url = "users? Name = "+ encodeuri ($ (" # username "). val () + "& Password =" + encodeuri ($ ("# userpassword "). val () + "& type =" + encodeuri (input [I]. value); // encodeuri handles Chinese garbled characters