Problems caused by Android Access server (TOMCAT) garbled
1, the browser to the server to send the request can be divided into 2 kinds: get, post;delete, head, etc. do not repeat.
Get mode:
The most important feature of knocking the address directly from the browser is that the parameter is directly behind the address.
Post mode: Form submission, and so on.
2. Access process:
In the browser, enter the address –> the browser to encode the Chinese –> sent to the server-server for decoding
How the browser encoding and the server decoding character set inconsistent will cause garbled problems.
3, garbled to solve
The default browser uses UTF-8 encoding (ie default GBK can certainly be set via META tag)
The server (TOMCAT) uses iso-8859-1 decoding by default. Iso-8859-1 is not supported in Chinese, that is, not to do processing, Chinese is a certain garbled.
Post Mode resolution:
For example, form submission, set request.setcharacterencoding ("UTF-8") in a servlet or filter, and it will be a good solution.
Get mode: Simply set request.setcharacterencoding ("UTF-8") is useless, so we change the default iso-8859-1 encoding to UTF-8, in the server.xml of the Tomcat configuration file:
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "UTF-8"/>
Add Uriencoding=utf-8
4. Access in Android:
Post way, through the HttpURLConnection encapsulation Post request "concrete implementation of Baidu", the Post method parameter is to be packaged sent, not directly following the URL. For example: http://www.demo.com?p=123 This is not a post transfer parameter.
Get way, through the httpurlconnection can be very simple implementation, but will find that it is easy to garbled problems.
First: Add Uriencoding=utf-8 work completed, or will be sent garbled.
This is because the above procedure mentions that the browser encodes Chinese , here we send the request directly, and we do not encode the process, so we need to manually code it ourselves, namely:
String name =urlencoder.encode ("Long Live China", "UTF-8");
So we simulated the browser encoding, and then sent to the server, the server decoding also changed to UTF-8, and then can be happy to play.
Original link This article by Bean John Blog Backup expert remote One click release
Issues with Android Access server (TOMCAT) garbled (reproduced)