I do the test when used to Jsp/servlet to MySQL to write the data, but the Chinese are always garbled, this morning tangled up a long time to be done, to share my solution
First look at where to start from where the garbled, as long as the unified code, there will be no garbled, the following to Uft-8 (personally think the best) as an example, detailed description:
1, if the garbled is from the JSP page appears, JSP head page plus:
Add a label to the head tag.
2, if the garbled is in the servlet appears, there are two ways:
One is in each servlet doget and Dopost method head Plus
Request.setcharacterencoding ("Utf-8″");
The second most insurance, once and for all, is dedicated to write a filter class, also known as internationalization, class name Setcharacterencodingfilter content as follows
Then add the following code to the Web-inf web.xml:
Then add the following code to the Web-inf Web.xml: A that's it.
3, if there are garbled, is the problem of MySQL database
1 to ensure that the database when the database code selected is Utf-8, preferably in each table also specify the encoding format, mysql default is Latin1
2 If the MySQL version is more than 4.x, the database is still garbled, there are the following two ways to solve:
One is to specify the encoding in the code that connects the database:
String url = "JDBC:MYSQL://LOCALHOST:3306/TEST2?AUTORECONNECT=TRUE&USEUNICODE=TRUE&CHARACTERENCODING=GBK &mysqlEncoding=utf8″;
If it's still not working, it's
Show variables like ' collation_% ';
This command to view the default character set, if not Utf-8 My.ini (Windows) or MY.CNF (Linux) to modify the appropriate encoding to UTF8 after the restart of the MySQL server is OK