A full set of solutions to jsp value-passing jsp database garbled
Solution to pass jsp value to jsp Chinese garbled value to database garbled
All UTF-8 encoding is used.
1. Select UTF-8 encoding for the part on the encoding page when installing mysql.
2 select Character Set sorting rules all utf8 when creating a database -- UTF-8 Unicode utf8_general_ci
3. When creating a table, all the character set sorting rules are the same as those above.
It's okay to go to the database.
Next, the jsp end
4. Add headers of all jsp pages
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<% @ Page contentType = "text/html; charset = UTF-8" %>
5. Connect to the assumervlet of the database
String cc = "com. mysql. jdbc. Driver ";
String server = "jdbc: mysql: // FIG: 3306/test1? UseUnicode = true & amp; characterEncoding = UTF-8 ";
String user = "root ";
String pwd = "";
6. The project's web. xml header
7. tomcat friends are using server. xml in the configuration
Header
Next, someone said in the server. xml configuration file for tomcat:
Port = "8080" maxHttpHeaderSize = "8192"
MaxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
EnableLookups = "false" redirectPort = "8443" acceptCount = "100"
ConnectionTimeout = "20000" disableUploadTimeout = "true"/>
URIEncoding = "UTF-8"
8. If you forget to use UTF-8 when creating a project, right-click the resource settings in the project properties.
After all the modifications are completed, I believe you will not see garbled characters.
It should be emphasized that you can use the strong Conversion Function If jsp transfers the value.
String name = request. getParameter ("name"); change
String name = new String (request. getParameter ("name"). getBytes ("ISO-8859-1"), "UTF-8 ");
This will display Chinese characters. Of course, it is very troublesome.