The ultimate solution to the problem of interactive garbled data between foreground and server

Source: Internet
Author: User

The problem of garbled characters in development is really annoying. Let's summarize today.

1.post Way to submit data Chinese garbled processing

Post way to submit the data garbled problem is easier to solve, generally the server-side encoding to the same as the front page on the line. For example, the page JSP is Utf-8, then the background is

Request.setcharacterencoding ("UTF-8");

2.get Way Submission and link submission

Both of these methods are directly to the parameters of the URL to upload to the server, they go URI

Workaround:

(1) Modify the Tomcat configuration file Server.xml, modify the Uriencoding property in connector, which defaults to "Iso8859-1"

1  <  port= "8080"  protocol= "http/1.1"2                ConnectionTimeout= "20000"3               redirectport= "8443"  uriencoding= ' utf-8 '/>

(2) Do not change the tomcat configuration, the parameters passed back to convert the code

   String data = Request.getparameter ("paramname");

   byte[] Source = data.getbytes ("iso8859-1");

   data = New String (source, "UTF-8");

So the data obtained is not garbled. Of course, if uriencoding in Tomcat is changed to another encoding, the iso8859-1 will be replaced with the corresponding encoding .

The ultimate solution to the problem of interactive garbled data between foreground and server

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.