In the process of using jsp (the preferred choice for SUN enterprise-level applications), Chinese garbled characters are the biggest headache, the following are the garbled issues I encountered during software development and solutions.
1. jsp (preferred for SUN Enterprise Applications) page garbled
The reason for this Garbled text is that the character set encoding is not specified on the page. Solution: Use the following code to specify the character set encoding at the beginning of the page,
2. Database garbled characters
This Garbled text will make Chinese characters you inserted into the database Garbled text or Garbled text when reading the display. The solution is as follows:
Add the encoding character set to the database connection string
String Url = "jdbc: MySQL (the best combination with PHP): // localhost/digitgulf? User = root & password = root & useUnicode = true & characterEncoding = GB2312 ";
Use the following code on the page:
Response. setContentType ("text/html; charset = gb2312 ");
Request. setCharacterEncoding ("gb2312 ");
3. garbled characters are transmitted as parameters in Chinese.
When we pass a Chinese character as a parameter to another page, garbled characters also occur. The solution is as follows:
Encode parameters when passing parameters, such
RearshRes. jsp (preferred for SUN Enterprise Applications )? Keywords = "+ java.net. URLEncoder. encode (keywords)
Then, use the following statement on the receiving parameters page to receive
Keywords = new String (request. getParameter ("keywords"). getBytes ("8859_1 "));
The above is the garbled problem encountered at the present stage. The core issue of garbled code is the character set encoding problem. As long as you master this problem, the general garbled problem can be solved.