MySQL solves Chinese garbled characters and filters Chinese Characters

Source: Internet
Author: User

I. MySQL character set (available everywhere)
Environment (select best support for multilingualism or utf8 ),
Databases, tables, and fields
The rules are as follows:
If the library is not specified, the character set in the environment is used.
If the table is not specified, the character set by the database is used.
If the field is not specified, the character set for the table is used.

Generally, the character set of the table is specified during table creation. It is best to set the MySQL environment, database, and table to the same character set.
Reduce unnecessary troubles.

MySQL database settings
A) Windows: when MySQL is installed in windows, select UTF-8 for encoding. Check the my and INI files in the MySQL installation directory and add default-character-set = utf8 under the [mysqld] section.

2. Solve Chinese garbled characters
Add "useunicode = true & characterencoding = utf8" to the URL"

New String (request. getparameter ("test"). getbytes ("iso-8859-1"), "GBK ")

However, such code is not a solution, which will increase the complexity of the program,
Finally, the perfect solution is found. In tomcat, you only need simple configuration to introduce two files.
Easy to handle.
3. Use filters to solve Chinese garbled characters
In tomcat, The webapps/JSP-examples/web_inf/classes/filter directory
Find the two files requestdumperfilter. Java, setcharacterencodingfilter. Java,
Copy to the filters package

Step 2: Configure web. xml

Add this section to Web. XML (remember to add it between the display-name item and the servlet item, because Web. xml
The DTD file set in the file header limits the order of each item)

......

<Filter>

<Filter-Name> set character encoding </filter-Name>

<Filter-class> filters. setcharacterencodingfilter </filter-class>

<Init-param>

<Param-Name> encoding </param-Name>

<Param-value> utf8 </param-value>

</Init-param>

</Filter>

<Filter-mapping>

<Filter-Name> set character encoding </filter-Name>

<URL-pattern>/* </url-pattern>

</Filter-mapping>

......
Writing JSP in the future is like writing a book.
<% @ Page contenttype = "text/html"; charset = utf8 "%>
<Meta http-equiv = Content-Type content = "text/html"; charset = utf8 ">

Four first principle: All encoding places, unified set as UTF-8, such as traditional, simplified, Japanese, Korean... )
I. Question about downloading a Chinese file name
A) Tomcat: Modify the conf/server. xml file under the tomcat installation directory, add uriencoding = "UTF-8 "/
<Connector Port = "8080"... uriencoding = "UTF-8"/>

B) JBoss: Install the server/default/deploy/jbossweb-tomcat55.sar/server. XML in the directory
<Connector Port = "8080"... uriencoding = "UTF-8 "/
 

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.