Chinese processing is very troublesome during development. Some content is recorded as follows:
JSP file encoding: UTF-8
Tomcat URI encoding: UTF-8
1. Get form data.
String atest = request. getparameter ("test ");
If (Atest! = NULL &&! Atest. Equals (""){
Atest = new string (Atest. getbytes ("ISO-8859-1"), "UTF-8 ")
}
2. encoding is related to the system platform when file operations are involved. windows platform File System Code: cp1252, FreeBSD File System Code: ISO-8859-1. cp1252 in Windows supports Chinese by default, while it needs to be converted under FreeBSD. freeBSD is shown as follows:
// Convert to system Encoding
Atest = new string (Atest. getbytes ("GBK"), "ISO-8859-1 "));
// Convert to Chinese
Atest = new string (Atest. getbytes ("ISO-8859-1"), "GBK "));
When the Chinese character is output to the log, it is displayed normally only when it is converted to the encoding type.
3. parameters after the URL. When the page jumps, data cannot be transmitted through the form. Therefore, the data can only be added to the URL. The processing methods of different platforms are different.
In Windows:
Read: parses the query string directly. The processing of the value (aparameter) is as follows:
Java.net. urldecoder. Decode (aparameter). getbytes ("ISO-8859-1"), "GBK ")
Settings: Convert Chinese to ISO-8859-1 first
Response. sendredirect (new string (aurl. getbytes ("GBK"), "ISO-8859-1 "))