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