The error message returned when the get method is garbled.

Source: Internet
Author: User
This is caused by the server, such as Tomcat receives the get method by default using ISO-8859-1 encoding, while the browser sends the text encoding is consistent with the page encoding, if the page is using UTF-8 encoding get method text is naturally using UTF-8 encoding, but the receiving server is not set with the ISO-8859-1 encoding to receive, the Chinese will naturally become garbled, however, since ISO-8859-1 encoding is single-byte encoding, we can use getbytes ("ISO-8859-1"), "UTF-8" to re-convert the text to UTF-8 encoding.

The first sent text is UTF-8 encoded and Tomcat is encoded with the wrong ISO-8859-1 after receiving, so that getbytes ("ISO-8859-1") will get the correct UTF-8 encoded byte array again, then use new
String (request. getparameter ("something"). getbytes ("ISO-8859-1"), "UTF-8") recode byte into UTF-8-encoded text so that the text is correct.

If Tomcat is used
<Connector Port = "80" protocol = "HTTP/1.1"
Connectiontimeout = "20000" redirectport = "8443" uriencoding = "UTF-8"/>
The uriencoding at the end is to set the get method encoding. If the encoding type received by the URL is not specified, it will be automatically encoded by the ISO-8859-1.

The error message returned when the get method is garbled.

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.