Jsp Chinese problem solution (Full Version)

Source: Internet
Author: User

It is common to develop java applications with garbled characters. After all, unicode is not widely used, and gb2312 (including gbk simplified and big5 traditional) is used) in the system to correctly implement the Chinese display and database storage is the most basic requirement. 1. First, developers should clarify why they encounter Garbled text and Garbled text (meaningless symbols are a string of question marks or other things ). When a newbie encounters a bunch of messy characters, he is often at a loss. The most direct reflection is to open google search for "java Chinese" (the query frequency of this string on the search engine is very high ), then, let's look at other people's solutions one by one. There is no error in doing so, but it is difficult to achieve the goal. The reason is described below. In short, there are many reasons for Garbled text, and the solution is completely different.


It is common to develop java applications with garbled characters. After all, unicode is not widely used. It must be correctly implemented in systems that use gb2312 (including gbk simplified and big5 traditional ).

Chinese display and database storage are the most basic requirements.


1. First, developers should clarify why they encounter Garbled text and Garbled text (meaningless symbols are a string of question marks or other things ).
When a newbie encounters a bunch of messy characters, he is often at a loss. The most direct reflection is to open google search for "java Chinese" (the query frequency of this string on the search engine is very high ),

Then, let's look at other people's solutions one by one. There is no error in doing so, but it is difficult to achieve the goal. The reason is described below.
In short, there are many reasons for Garbled text, and the solution is completely different. To solve the problem, you must first analyze your own "context environment ".

2. What information is required to determine the root cause of garbled characters in the project.
A. operating system used by developers
B. j2ee container name and version
C. Database Name, version (exact version), and jdbc driver version
D. garbled source code (such as system out or jsp page. If it is in jsp, it is also important to declare the header)

3. How to preliminarily analyze the causes of garbled characters.
With the above information, you can post for help. I believe that you will soon be able to come up with an effective solution on javaworld and other forums.
Of course, you can't always rely on posting for help. You should also try to solve the problem on your own. How can this problem be solved?
A. Analyze the encoding of your garbled code. This is not difficult, for example
System. out. println (testString );
This section contains garbled characters, so you may wish to use the exhaustive method to guess its actual encoding format.
System. out. println (new String (testString. getBytes ("ISO-8859-1"), "gb2312 ″));
System. out. println (new String (testString. getBytes ("UTF8"), "gb2312 ″));
System. out. println (new String (testString. getBytes ("GB2312"), "gb2312 ″));
System. out. println (new String (testString. getBytes ("GBK"), "gb2312 ″));
System. out. println (new String (testString. getBytes ("BIG5"), "gb2312 ″));
Wait, the above Code means to read the "garbled" testString in the specified encoding format and convert it to gb2312 (here, we only use Chinese as an example)
Then you can see which of the converted results is OK...

B. If you can use the above steps to obtain the correct Chinese characters, it means that your data is certainly in use, but it is not displayed correctly on the interface. The second step is to correct your view.

Check whether the correct page encoding is selected in jsp.

Here, we need to declare that many people misunderstand the <% @ page contentType = "text/html; charset = GB2312" %> command and <META http-equiv = Content-Type

Content = "text/html; charset = gb2312"> the two are different. Many articles on the Internet usually refer to unicode or gb2312 storage in databases when talking about Chinese.

  • 9 pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • Next Page

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.