Solve Chinese problems in MySQL, Struts servlet, and JSP

Source: Internet
Author: User

There are many

(1) Find My. ini in the MySQL directory
Open it, find the default-character-Set setting, and change it:
Default-character-set = gb2312

If the version is 5.0 or later, you can set it in the configuration panel:
For details, see:Http://ycoe.cnblogs.com/articles/354485.html

(2) string newname = new string (name. getbytes ("iso-8859-1"), "GBK ");

1. Make sure that the character set you used when installing MySQL is GBK.
------> 1. <% @ page Language = "Java" pageencoding = "UTF-8" %>
------> 2. If you have a Chinese character in JSP, it can be displayed normally, and a form with a struts label can also be displayed as Chinese, however, when you submit Chinese characters in the form, it turns into garbled characters.
------> 3. After it turns into garbled characters, an error will occur when comparing the data with the database, and you will see ????? Garbled
------> 4. The solution is to delete <% @ page Language = "Java" pageencoding = "UTF-8" %> from the first line
<% @ Page contenttype = "text/html; charset = gb2312" %>
And
<Head> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/> (Note that the first line must be in the head)
------> 5. When using post to submit data, it will also become garbled. The solution is

Put the WEB-INF/Web. xml under the project file
Add the followingCode
<Filter>
<Filter-Name> set character encoding </filter-Name>
<Filter-class> filters. setcharacterencodingfilter </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> GBK </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-Name> set character encoding </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

Then copy the WEB-INF/classes/filter directory in the servlet to the corresponding directory in the project, so as to solve the problem caused by post submission.
OK! Change to struts Chinese

Servlet Chinese problems

Response. setcontenttype ("text/html; charset = gb2312 ");
Request. setcharacterencoding ("gb2312 ");

Struts Chinese problems
Compile the resource file with native2ascii.exe and place it in the original location.

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.