Why does Chinese garbled characters occur when JavaScript uploads Chinese characters to actions?

Source: Internet
Author: User

Today, I recorded a small problem: for example, the text box on the page or the obtained "Chinese value" is garbled, and then I went to the database to find it and returned an error! I found many methods and found that they are not applicable. The solution is just one sentence. Solution: In the returned action, make the following changes to the str string. OK! Str = new String (str. getBytes ("iso-8859-1"), "UTF-8"); analysis: knows its natural, know its natural: The information submitted from the browser is committed in bytes of the server, Server Resolution, finally, it is converted to the corresponding information. It is parsed into bytes. When it is parsed back, it will be parsed using the server's corresponding encoding. (Tomcat seems to be a ISO-8859-1 encoding by default) so you have to generate a new set of character you want, that is, declared as: UTF-8; the default encoding and requirement encoding vary according to different "requirements" and "containers!

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.