Chinese processing of Tomcat (3):
The previous nonsense, now let's analyze a few examples:
1) If you are used in JSP:
<% @ page contenttype = "text / html; charset = shift_jis"%>
He actually specifies the type of response and characters, which specifies the character encoding of Response is Shift_JIS.
When constructing String in JSP, if you do not specify String encoding, the code used by String is specified by charset; if Charset does not specify the coding of the character, then, use ISO-8859-1
Note that if you do not specify the Requset encoding, the String obtained from Request is ISO-8859-1 encoded. (The last article has been told.), He and the charSet are no relationship.
If the String's code to be output, the case where the Response's encoding is different, it is likely to appear garbled.
for example:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> // /// Specifying Response encoding as Chinese Simplified, then all the characters to be output should be used to adapt to GB2312
hEAD>
<%
String name = Request.getParameter ("name"); get the parameter value of the client, no specified request encoding, so it is String encoded as ISO-8859-1.
String name1 = new string (Name.getbytes ("ISO-8859-1"), "GB2312"); // Translate into Chinese Simplified Codes
String name2 = "Hello"; / Directly Define String, use the reponse encoding, here is GB2312.
String name21 = new string (Name2.GetBytes ("ISO-8859-1"), "GB2312"); transformation from NAME2
System.out.println ("Name1 IS GB2312" Name1);
System.out.println ("Name IS ISO-8859-1" Name);
System.out.Println ("Name21 IS Direct" Name21);
System.out.println ("we all");
%>