A full set of solutions to jsp value-passing jsp database garbled

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.