js| Question | Chinese abstract: There has been quite a lot of discussion about the problems of Java application in dealing with Chinese, and unlike most of the discussions, this paper discusses the problems of Java language processing in Chinese from the angle of input and output of Chinese characters.
Although there is no shortage of discussion about the problems that Java has in dealing with Chinese characters, there is no official standard for Java technology, because it involves a wide range of content (more than 10 related technologies), a wide variety of technology vendors, Java-oriented Web servers, application servers, and JDBC database drivers. Therefore, Java application in the processing of Chinese when there are inherent problems, but also with the selection of servers, drivers of different issues related to the platform. In other words, the portability of Java code is discounted when dealing with Chinese problems.
In general, the Chinese processing of Java is more concentrated in JSP technology application and Java database access process. This is because both JSP applications and JDBC database access involve the interaction between Java programs and another application system, which inevitably requires data interaction and parameter transfer between the systems. The place where Java handles Chinese problems is often where the data is read and exported.
The Chinese problem that the JSP program should pay attention to
As an example of the JSP application of Tomcat 3.2.1, it is generally possible to use the following code-cast function to convert the code into a Chinese problem.
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;
}
}
Note that before using this function, we need to analyze the reasons why Chinese can not be correctly exported, but not all of the Chinese to deal with the problem is solved by this method. For example, if you forget to define the JSP output code as GB2312 or GBK, the resulting Chinese cannot be correctly exported and cannot be solved with this function. A good habit is to define the character set that the program will output in the first line of the file when we write each JSP page, such as
<%@ page contenttype= "text/html; CHARSET=GBK "%> or
<%@ page contenttype= "text/html; charset=gb2312 "%>
For some JSP versions that do not support the definition of output, we can also make the following settings:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
Also note that this function is designed to address code that does not correctly output Chinese, rather than a general-purpose function that guarantees the correct output of the medium character. Because the Chinese characters cannot be correctly exported or read because of the difference between the encoding of this character and the default character set encoding of the system (or the character set to be output, which is generally the same), So before we can apply this function we have to determine whether the encoding of the characters we are going to read or output is the same as the system default character set encoding.
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.