What is the most difficult to process in JSP? The younger brother wanted to install the JSP JavaBean Forum a few days ago, after 3 days, understand the answer is the problem of processing Chinese in Java.
The character encoding adopted by Acjspbbs is GBK. I use the Win2K system. It should be water to the stream, but it is actually found that it is used in the JavaBean to save the database statement is ISO8859-1 encoding, directly leading All the materials taken out from the database garbled, including: the title of the forum name, the title and content of the user sending the title.
In fact, the Java system will uniformly use the UTF-8 encoding in the Java system, while the operating system default encoding is used before internal conversion, including input and output. If you want to not mess, you only need the "Unified Java System Input, Output, and Operating System", which is also a principle for processing Java system Chinese characters. The reason is due to the cross-platform characteristics of Java, the character set must be given by the specific operating system.
This allows for a way to solve the JSP garbled, which mainly needs to grasp three links: 1. Specify a character set when developing and compiling the code, such as ISO-8859-1 (Western system mostly used this) 2 Determine the character set of the operating system and 1 unity, such as using ISO-8859-1, such OS has a lot, Linux is whip 3, if developed JSP, each page clearly specifies the character set: <% @ Page ContentType = "text / html; charSet = ISO8859-1"%>
This reaches the front goal, unified the character encoding of the three.
Although this system is very good, there is no garbled problem, but it is obviously exchanged for the cost of damage cross-platform characteristics. I want to solve the problem at all, it seems that only the Java system is unified as UTF-8 encoding, which requires all the entrances.
The following sections need to be aware of the following sections: 1. Specify the character set to UTF-82 when developed and compile, use a filter to convert all requests to UTF-8 character set If it is assigned to control in servlet's Filter Write Request.SetCharacterencoding ("UTF-8") If you use a JSP page, you define <% @ page contentty = "text / html; charset = utf-8"%> 3, including databases on all outputs Specify the character set UTF-8 in connection
In addition: If you are doing twice open, you need to recompile the package, specify UTF-8 encoding
Attachment: The syntax specified in the specified character set is Javac -Encoding
Description: Among them here is to quote others, but I have used it myself is an absolutely effective solution.