Form form submitted in Chinese garbled (foreground Chinese to Java background garbled) problem and solve a problem:
The Chinese content in the page input box is garbled in the background, which causes the search function to fail; (see reproduced in detail later)
Second, Reason:
The browser's default encoding format for data is UTF-8, but Tomcat (TOMCAT7 and below) defaults to iso-8859-1 decoding, resulting in garbled characters;
Third, the solution:
3.1 Re-structuring the parameter string in the background;
Code one: activityname = new String (activityname.getbytes ("iso-8859-1"), "Utf-8"); One line of code can code two: Activityname = Java.net.URLEncoder.encode (Activityname, "iso-8859-1"); activityname = Java.net.URLDecoder.decode (Activityname, "UTF-8");
3.2 Directly change the Tomcat configuration
3.3 Many other ways to Baidu
Iv. Reproduction and resolution:
V. References:
- Chinese garbled in Java Urlencoder.encode method to call two resolution-CSDN blog http://blog.csdn.net/kongqz/article/details/9028111 (I just look at this solution)
- Post in Java, Chinese encoding & decoding issues-Dream it POSSIBLE-CSDN blog http://blog.csdn.net/hu_zhiting/article/details/52088245 (The tutorials are well written and there are many workarounds)
- Request and Response Setcharacterencoding () method-Kong_lev's blog-csdn blog http://blog.csdn.net/kong_lev/article/details/ 73071198 (Dapper)
- URL request in Chinese garbled processing-csdn blog http://blog.csdn.net/zhengyang7754/article/details/47263599 (Very long ... But did not read it)
<wiz_tmp_tag id= "Wiz-table-range-border" contenteditable= "false" style= "Display:none;" >
Form form Submission Chinese garbled (foreground Chinese to Java background garbled) problems and solutions