Several analysis principles on Java Chinese

Source: Internet
Author: User

Introduction
Although there are already many discussions on Java's Chinese processing problems, Java technology involves a wide range of content (J2EE includes more than a dozen related technologies), and there are many technical vendors, java-oriented Web servers, application servers, and JDBC database drivers do not have official standards, therefore, Java applications have inherent problems in the process of processing Chinese characters, and there are also the variability of Java Chinese problems caused by the selection of servers and drivers, this increases the complexity of the problem. So, how can we find the crux of the problem in such a complicated phenomenon?
General solutions to Java Chinese problems
In fact, Java's Chinese problems are caused by the difference between the default encoding format used by Java applications and the encoding format of the characters to be read by the target or application (see Document 1 for details ). There are usually four methods to solve the Chinese problem of Java:
1) select the localized Chinese version of JDK. Although Java2 JDK's Chinese localized version (http://java.sun.com/products/jdk/1.2/chinesejdk.html) is not an official version, Sun does not promise to upgrade it, however, it is still a solution to the Java Chinese problem.
2) select the appropriate compilation parameters. For the international Java version, we can also specify a specific compiler to support the compilation results of Java applications in Chinese. For example, you can use javac-encoding big5 sourcefile. java and javac-encoding gb2312 sourcefile. java to compile the source program.
3) implement character encoding conversion code through programming. It has become a common practice to solve the Chinese problem of Java through programming. The following is the most common character encoding conversion function, which converts the character encoding format to the GBK encoding format of the Chinese Windows system.
Public static String toChinese (String strvalue)
{
Try {
If (strvalue = null)
Return null;
Else
{
Strvalue = new String (strvalue. getBytes ("ISO8859_1"), "GBK ");
Return strvalue;
}
} Catch (Exception e ){
Return null;
}
}

4) define the character output set. For JSP applications, you can use <% @ page contentType = "text/html; charset = GBK" %> or <% @ page contentType = "text/html; charset = GB2312 "%> to define the character output set of the JSP page. Of course, we can also define the output set of characters through the HTML tag <META HTTP-EQUIV = "Content-Type" CONTENT = "text/html; charset = gb2312">.

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.