Java Chinese Identification Problem Complete Solution [1]

xiaoxiao2021-03-06  126

Copyright belongs to Shi Xiang (Elpha (AT) MSN (Dot) COM)

Contact: MSN: Ealpha (AT) MSN (Dot) COM

QQ: 9690501

============================================================================================================================================================================================================= ============================

Since some netizens reminders that the article is not very comprehensive, I will send a new class to solve the problem of general Chinese!

============================================================================================================================================================================================================= ============================

Java cannot correctly display Chinese is generally as follows

Many cases should determine the transcoding method for environment variables, debugging environments! The following methods can solve most of the problems!

1. If the JDBC can access Chinese correctly. Try ContentType = "text / html chaaterset = GB2312" in the Page instruction.

Example: <% @? Page? Language = "java" ?? contenttype = "text / html;? Charset = GB2312"? Import = "java.sql. *"%>

2, the JDBC cannot be properly stored correctly (1) string address = request.getParameter ("address"); byte [] tmpByte = address.getbytes ("ISO8859_1"); address = new string (tmpByte); (2) String Name = Request.getParameter ("name"); name = new string (Name.getbytes ("GB2312"), "ISO8859_1");

"ISO8859_1" and "GB2312" can try to exchange

example:

/ ************************************************** ************************* Nickname is a hypothetical field TM Nickname transcoding time temporary field *********** *********************************************************** ************ / STRING NICKNAME = rs.getstring ("nickname"). Trim (); // Read the information **** Byte [] TMNICKNAME = Nickname.getbytes ("ISO8859_1" ); // Recode information to the information of TM **** temporary storage data nickname = new string (tmnickname); // 转 转 t t ****

转载请注明原文地址:https://www.9cbs.com/read-127097.html

New Post(0)