Java cannot correctly display Chinese characters in the following two cases:
In many cases, you should determine the transcoding mode based on environment variables and debugging environment! The following methods can solve most of the problems!
1. If JDBC can properly access Chinese characters.
In the PAGE command, try contenttype = "text/htmlchaterset = gb2312"
Example:
<% @ Pagelanguage = "java" contentType = "text/html; charset = GB2312" import = "java. SQL. *" %>
2. Chinese characters cannot be properly stored in JDBC
(1) Stringaddress = request. getParameter ("address ");
Byte [] tmpbyte = address. getBytes ("ISO8859_1 ");
Address = newString (tmpbyte );
(2)
Stringname = request. getParameter ("name ");
Name = newString (name. getBytes ("gb2312"), "ISO8859_1 ");
"ISO8859_1" and "gb2312" can be switched
Example:
/*************************************** ***********************************
Nickname is a hypothetical field.
Temporary fields during tmnickname Transcoding
**************************************** **********************************/
Stringnickname = rs. getString ("nickname"). trim (); // read information ****
Byte [] tmnickname = nickname. getBytes ("ISO8859_1"); // encode and convert the information into tm ***** temporary data storage
Nickname = newString (tmnickname); // assign the converted tm *** to the field ****