JSP, servlet About Chinese issues again

zhaozj2021-02-08  249

Www.dukejava.com This week, Cool Posts, every week, welcome!

In JSP, Chinese garbled often makes people tempted. For a common countermeasure for Chinese processing, the mainly visible online is the following two types: <% @ page contentType = "text / html; charSet = GB2312"%> or: <% string hi = "Hello"; byte [] TMPBYTE = Hi.GetBytes ("ISO8859_1"); Hi = new string (tmpByte); out.print (hi);%> Virtual Xiaolong Pavilion also modified the above two methods, which turned from version 1.1. By simple summary, the Chinese processing in the example occurs in the following places: 1 In the URL, the Chinese parameter is included, you can read it directly. For example: <% = Request.getParameter ("ShowWord")%> 2 related to the database related SQL operations here useless there is no problem. 3 Read the Chinese value submitted in the HTML Form form to encode in JSWDK, relatively simple, write like: string name1 = new string (Request.getParameter ("User_ID"). GetBytes ("ISO8859_1"); additional, in addition, Under the support of JDK1.3, do not need to join <% @ page contenttype = "text / html; charset = GB2312"%> below JDK1.2.2, even if two methods are used simultaneously. And in the RESIN platform, the situation is better. Just join: <% @ Page ContentType = "text / html; charset = GB2312"%> can handle Chinese. If adding codes, it is not correct. 5 The Chinese contained in the session in JSWDK, strangely display correctly if the value read from the Form is encoded correctly; but directly gives Chinese values. The RESIN platform is very good, the same. 6 Display Chinese correctly after the variable value is verified. For example, the following procedure: <% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% string hi = "Hello"; Byte [] TMPBYTE = Hi .getbytes ("ISO8859_1"); hi = new string (tmpByte); out.print (hi);%> is also JSWDK1.0.1, the above representation is not problematic in JDK1.2.2 But in JDK1.3, it cannot be displayed. The RESIN platform is very good, I have the test, only the test, only need to make can also display Chinese correctly. Experience: JSWDK may only be used for general development, stability, and other problems may not be as commercial software.

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

New Post(0)