Adding Chinese data to MySQL database garbled characters on the JSP page

Source: Internet
Author: User

Entering Chinese data on the JSP page and saving it to the MySQL database are garbled characters. After reading data from the database, it is still garbled on the JSP page. To solve this problem, consider the following:

 

1. Obtain the MySQL Character Set

 

The command to view the MySQL character set is:

 

Mysql> show variables like "character_set _ % ";

 

 

 

Character_set_system always UTF-8

 

It is best to keep these five items consistent,

Character_set_client
Character_set_connection
Character_set_database
Character_set_results
Character_set_server

 

2. Specify the encoding format on the JSP page to ensure that it is consistent with the MySQL character set:

 

<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>

 

3. Add a character encoding filter to Web. xml. The encoding method must be consistent with that of MySQL:

 

<! -- Famous character encoding filter --> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <filter-class> <br/> Org. springframework. web. filter. characterencodingfilter <br/> </filter-class> <br/> <init-param> <br/> <param-Name> encoding </param-Name> <br/> <param-value> UTF-8 </param-value> <br/> </init-param> <br/> </filter> </P> <p> <filter- mapping> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <URL-pattern> *. DO </url-pattern> <br/> </filter-mapping>

 

Note: The encoding format of the added data page and the displayed data page must be consistent. Otherwise, no garbled characters will appear in the database, and garbled characters will appear in the database.

Related Article

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.