1. Add a filter to the configuration file web.xml
init-param>
filter>
filter-mapping>
2. Database storage problem
If it is DB2, click the database in the configuration center and set the parameter to set the encoding problem.
If you are using mysql, you should set it as follows when configuring JDBC.
Useunicode = true & characterencoding = GB2312]]> value> property> bean> 3.jsp file decoding JSP file start setting character set <% @ Page ContentType = "text / html; charset = GB2312"%> 4. Get characters using GetBytes ("Charset") E.g: String s = rs.getstring (rsmd.getcolumnname (i)). GetBytes ("ISO-8859-1"); IF (s! = null) New String (S, GBK ") Remarks: Reprinted Http://www.kfnet.cn/artical.kf?articalid=2222&belong=0&type=0 String.getBytes () Chinese code problem String's getBytes () method is to get the byte array of strings, which is well known. However, it is important to note that this method returns the byte array of the operating system default encoding format. If you don't take into account this when you use this method, you will find it on a platform. [Shielded Advertising] Good system, will have unexpected problems after placing another machine. For example, the following program, class testcharset {public static void main (String [] args) {new testcharset (). Execute ();} private void execute () {string s = "hello! Hello!"; Byte [] Bytes = s.getbytes (); system.out.println ("Bytes LengHT is:" bytes.length);}} Under a Chinese WindowsXP system, running, the result is: bytes Lenet is: 12 but if you put it In English Unix Environment: $ Java Testcharset Bytes LengHT IS: 9 If your program depends on this result, problems will be caused in subsequent operations. Why is the result in a system 12, but the other changed to 9? The above has been mentioned, which is related to the platform (encoding). In the Chinese operating system, the getBytes method returns a Bikk or GB2312's Chinese encoded byte array, wherein the Chinese characters, each comprise two bytes. In the English platform, the general default code is "ISO-8859-1", each character takes only one byte (regardless of whether it is non-Latin characters). Code support in Java Java is a multi-country code. In Java, the characters are stored in Unicode. For example, the Unicode encoding of "You" word is "4F60", we can verify the following experiment code: Class testcharset {public static void main (string [] args) {char c = 'you'; int i = C; system.out.println (c); system.out.println (i);}} No matter what you are in any Execution on the platform, there will be the same output: ----------------- Output ------------------ You 20320 20320 is an integer value of Unicode "4F60". In fact, you can refer to the above class, you can find that characters "you" (or any other Chinese string) in the generated .class file itself is stored in Unicode encoding: Char c = '/ u4f60'; ... even if you know the encoded encoding format, such as Javac -Encoding GBK Testcharset.java is still stored in a Unicode format in a Unicode format in a Unicode format. Skewers. Use string.getbytes (String Charset) So, in order to avoid this problem, I suggest that everyone will use the String.getbytes (String Charset) method in the encoding. Below we will extract the byte arrays of the ISO-8859-1 and GBK from the strings, see what results will be: Class testcharset {public static void main (String [] args) {new testcharset (). Execute ();} private void execute () {string s = "hello! Hello!"; Byte [] BYTESOO8859 = null; byte [ ] bytesgbk = null; try {bytesiso8859 = s.getbytes ("ISO-8859-1"); bytesgbk = s.getbytes ("gbk");} catch (java.io.unsupportedEncodingexception e) {E.PrintStackTrace (); } System.out.println ("------------ / n 8859 bytes:"); system.out.println ("Bytes IS:" arraytositing (bytesiso8859)); system. Out.println ("Hex Format IS:" EncodeHex (bytesiso8859); system.out.println (); system.out.println ("------------ / n GBK BYTES : "); System.out.println (" bytes IS: " arraytostring (bytesgbk); system.out.println (" HEX Format IS: " EncodeHex (Bytesgbk));} public static final string encodehex (byte [ ] bytes) {stringbuffer buff = new stringbuffer (bytes.length * 2); string b; for (int i = 0; i -------------- 8859 BYtes: BYTES IS: 72 101 108 108 111 33 63 63 63HEX Format IS: 48 65 6C 6C 6F 21 3F 3F 3F --------- ----- GBK BYTES: BYTES IS: 72 101 108 108 111 33 -95Hex Format IS: 48 65 6C 6C 6F 21 C4 E3 BA C3 A3 A1 visible, extracted in S The number of bytes of the 8859-1 format is 9, the Chinese characters become "63", "?"? "?", Some foreign procedures run during the domestic environment, often appear, top It is full of "?", Because the code does not perform correctly processing. GBK encoding of Chinese characters is correct in the byte array of extracted GBK codes. The GBK encoding of the character "You" "Good" "!" Is: "c4e3" "Bac3" "A3A1". You can use the following method when you need to restore the Byte array of GBK, you can use the following method: new string (byte [] bytes, string charSet