JSP Chinese Processing

Source: Internet
Author: User
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 "))

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.