How to solve java/j2ee Chinese problem

Source: Internet
Author: User

Most programmers have encountered the problem of Java in programming, but as long as you know the Java system of the Chinese problem principle, we can say goodbye to Chinese questions.

The oldest solution is to use string bytecode conversions, which is inconvenient, and we need to break the encapsulation of objects and do bytecode conversions.

Another way is to encode the Java EE container, if the Java EE application system out of the container, it will be garbled, and specify that the container configuration does not conform to the principle of Java application and container separation.

In the Java internal operation, all the strings involved are converted to UTF-8 encoding for operation. So, before being converted by Java, what is the character set of a string? Java always determines the initial encoding of a string based on the default coded character set of the operating system, and the input and output of the Java system is the default encoding of the operating system.

Therefore, if you can unify the input and output of the Java system and the encoding character set of the operating system 3, it will enable the Java system to correctly process and display Chinese characters. This is a principle to deal with the Java system characters, but in the actual project, it is difficult to grasp and control the input and output parts of the Java system correctly. In the Java EE, because of related to external browser and database, so the Chinese problem garbled appear very prominent.

The Java EE application is run in the Java EE container. In this system, there are many kinds of input channels: one is sent to the server through the page form package for request, the second is read through the database, and the 3rd kind of input is more complicated, the JSP is always compiled into servlet,jsp in the first run, and it often contains Chinese characters. When compiling with Javac, Java will be the initial encoding based on the default operating system encoding. Unless specifically specified, the default character set can be specified in Jbuilder/eclipse.

There are several output paths: The first is the output of the JSP page. Since the JSP page has been compiled into a servlet, the output encoding will also be selected based on the default encoding of the operating system, unless the output encoding is specified, and the output path is the database, which outputs the string to the database.

From this view, the input and output of a Java EE system is very complex, and is dynamic change, and it is running on a cross-platform, in the actual compilation and operation, may involve different operating systems, if the Java free based on the operating system to determine the input and output of the coded character set, This will not be controlled garbled.

Java is a cross-platform language, so that the character set problem must be solved by the specific system, so in a Java application system, the fundamental way to solve the Chinese garbled is to explicitly specify the entire application system uniform character set.

How to solve java/j2ee Chinese problem

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.