Solve the Problem of garbled data from the database to the page (all)

Source: Internet
Author: User
Tags sql client
In the WEB Project, character sets are set in many places, so it is best to unify them. Otherwise, it is hard to find them when errors occur. utf8 is used as an example. This is my favorite character set, let's see where character sets are set.

   First, MySQL server, in the configuration phase after installation, it is best to set the character set to utf8. The default value is Latin1, which is often garbled... In the installation area, find my. ini, where there are two character sets, you can also modify it.

   Then sqlyog is the SQL client, which is very easy to use. However, it takes a long time to find that SQL statements won't be written. I have to review it. I have checked this character set for a long time, I am not very familiar with the software... When creating a table, there is a button "Advanced properties" below, where you can modify the character set to utf8.

  After the SQL end is set, the character set in the project is displayed. First, add the following sentence to the front of the JSP page:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%>. Otherwise, an error may be reported during saving because the Chinese characters on the page are not recognized.

  After the page is completed, it is the configuration file.

  In applicationcontext. XML, it is better to add character sets to connect to the database in case of an error during connection.

  <Property name = "url"
   Value = "JDBC: mysql: // localhost: 3306/mmcwz? Useunicode = true & amp; characterencoding = UTF-8 ">
  </Property>

  In struts-config.xml, there will be such words above:

   <? XML version = "1.0" encoding = "UTF-8"?> Is automatically generated

  Important settings in Web. XML are filter settings.

  <Filter>
   <Filter-Name> characterencodingfilter </filter-Name>
   <Filter-class> org. springframework. Web. Filter. characterencodingfilter </filter-class>
   <Init-param>
     <Param-Name> encoding </param-Name>
     <Param-value> UTF-8 </param-value>
   </Init-param>
 </Filter>

After all this is done, there should be no problem. When asked, find out which step has the problem, just like in MySQL, use mmcwz, select * From announcementinfo; the data in the obtained table is garbled, indicating that sqlyog is inconsistent with the MySQL character set. After that, show create table announcementinfo and find that charset is GBK, the problem is found. You can also insert a post in the Java file. If garbled characters are found, they may be configuration problems or page settings problems.

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.