Java Chinese garbled solution

xiaoxiao2021-03-06  203

In Java-based programming, there is often a problem with the Chinese characters and display, such as a lot of garbled or question marks. This is because the default encoding mode in Java is Unicode, and the documents and DBs commonly used by Chinese people are based on GB2312 or BIG5 and other codes, so this problem will occur. I used to worry about this problem, and later I checked some information, I finally solved it. I know that there must be many friends will encounter this problem, so I have summed up, come out to let everyone share it. 1. Output Chinese in the web page. Java is encoded in network transmission is "ISO-8859-1", so it is necessary to transform when output, such as string str = "Chinese"; str = new string (str.getbytes ("GB2312"), "8859_1) "); But if the code is used when the program is compiled, the code is" GB2312 ", and this program is run on the Chinese platform, and this problem will not be noted. 2. Read Chinese from the parameters This is just as: str = new string (str.getbytes ("8859_1"), "GB2312"), "GB2312"); 3, a simpler method in operating the Chinese problem in DB Yes: In "Control Field", set the "region" to "English (US)". If there is a garbled, you can set the following: Take Chinese: str = new string (Str.getBytes)); Enter Chinese to DB: Str = New String (Str.getbytes ("ISO-8859 -1 ")); 4 in JSP Solution: In" Control Field ", set the" region "to" English (US) ". Join in the JSP page: If it still does not display properly, To perform the following conversion:, if: name = new string (Name.getbytes ("ISO-8859-1"), "GBK"); there will be no Chinese problem.

From: http://www.mifun.net/pengjie/myweb/Article/Article.asp? id = 201 & sort = jsp

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

New Post(0)