Summary of JSP Chinese garbled problem Solutions

Source: Internet
Author: User

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.

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.