Work accumulation (vii) The problem of Chinese garbled characters caused by--tomcat uriencoding

Source: Internet
Author: User

in the Java EE in the use of the Chinese search, in the background received the foreground data in the garbled, using the following way to Transcode:

try {keyword = new String (Cond.getkeyword (). GetBytes ("Iso-8859-1"), "Utf-8");} catch (Unsupportedencodingexception ex) {Ex.printstacktrace ();}

this solves the query failure problem caused by Chinese garbled characters when the test is deployed locally, but still does not work when the project is deployed to the test server. Because in addition to Chinese, English and numbers can be searched successfully, so it can be speculated that the character set is still a problem. Considering the fact that the database was not reached at the beginning of the query when the AJAX request was sent by the foreground, it is basically possible to exclude the configuration problem of the database character set, which has not been thought of for other reasons. It was later found that there was also a set of character sets in Tomcat, which, after comparison, was found to be due to the difference between local and test server Tomcat configurations.

by default, the character set used by Tomcat is iso-8859-1 :

<!--omit character Set declaration, default is Iso-8859-1--><connector port= "" "Protocol=" http/1.1 "connectiontimeout=" 20000 "Redirectpo rt= "18443"/>

and on the server The Tomcat configuration is as follows:

<!--declaration Character set--><connector port= "protocol=" http/1.1 "connectiontimeout=" 20000 "redirectport=" 18443 "UR iencoding= "UTF-8"/>

have modified Uriencoding After the problem is resolved. If there is a problem with Chinese garbled, and the database is set up correctly, you should think about confirming the character set used by Tomcat.

Finish.

Resources:

http://blog.csdn.net/hongqishi/article/details/7428380

This article is from the "barrel of fake dog excrement" blog, please be sure to keep this source http://xitongjiagoushi.blog.51cto.com/9975742/1662527

Work accumulation (vii) The problem of Chinese garbled characters caused by--tomcat uriencoding

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.