How to solve the garbled problem of Tomcat deployment GET request in Linux

Source: Internet
Author: User

By default, Tomcat's default encoding for requests is iso-8859-1, so that the characters we submit are considered iso-8859-1 encoded, so garbled when they are received in the program. Call Request.setcharacterencoding ("GBK") in the filter, then the Chinese characters on the post will be considered GBK encoded, and TOMCAT5 's code for GET requests does not recognize the encoding according to the filter settings, The default is still iso-8859-1, so even if your page is encoded using the default encoding, and then decoded using iso-8859-1, the results are incorrect.

Workaround:
Add two settings to <connector in Conf/server.xml in Tomcat
Usebodyencodingforuri= "true"//set post and get using the same encoding
uriencoding= "UTF-8"//URI using UTF-8 encoding processing

You can use string to provide the encoding conversion test, the requested parameter value:

name = new String (name.getbytes ("iso8859-1"), "UTF-8"). Trim ();

System.out.println ("Name:" + name)


How to solve the garbled problem of Tomcat deployment GET request in Linux

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.