Troubleshoot MySQL garbled

Source: Internet
Author: User
Tags mysql connection string java web

Summed up a few garbled problems hope that we all students can also learn to summarize
Java Web is very hope that everyone can learn. And also hope that we can in the learning process of the accumulation of relevant knowledge points

1, write in response <meta http-equiv= "Content-style-type" content= "text/html;charset=gb2312" >

2. Use new String (character variable. getBytes ("Iso-8859-1"), "gb2312")

3, in the JSP processing garbled problem is resolved as follows
String variable name = "Hello";
Lpara = Java.net.URLEncoder.encode (new String (variable name. GetBytes ("GBK"), "iso8859-1"));
<a href= "Yourservlet? Para=<%=lpara%> ">Test</a>
...
Yourservlet:
String lpara=request.getparameter ("Para");

4. Before you get the value of the variable (request.getparameter ("Control Name on Interface"), add the following code
Response.setcontenttype ("text/html;charset=gb2312");
Request.setcharacterencoding ("gb2312");
Respose.setcharacterencoding ("gb2312");

5. Ensure that the Chinese processing code in the servlet (3 lines of code in method 4) precedes the PrintWriter object
PrintWriter out = Response.getwriter ();


6, if the operation of the action of the operation is still garbled problem:
Note on the page Tanji right---code--to Chinese (OK)

7, if the above 1~6 operation or can not solve the Chinese problem:
Change server operation even if (a different Tom cat is posting or using JBoss release)

8. Provide reference only
Servlet Chinese garbled solve "use filter"

If it is not garbled when committing to the server side, it is the problem of MySQL connection string.
For example, I use GBK, the connection string is:
Jdbc:mysql://localhost:3306/test?autoreconnect=true&amp;useunicode=true&amp;characterencoding=gbk
That's what utf-8 should be.
Jdbc:mysql://localhost:3306/test?autoreconnect=true&amp;useunicode=true&amp;characterencoding=utf8

&amp; is the & symbol, I am in the XML file configuration practical, if you do not use XML configuration, it is written directly &

Troubleshoot MySQL garbled

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.