7.15 about resolving the get and post garbled problems of Javaweb background resolution Servlet

Source: Internet
Author: User

In the servlet learning, when the Web page input in English, although the Get method and the Post method can correctly pass the data to the data, but when the input box input in Chinese, when the background program to receive data, there will be garbled problems. This can be done by setting its encoding format, but not simply by setting it to "Utf-8", but in a variety of ways.

When committed with get, it needs to be set to new String (Name.getbytes ("iso-8859-1"), "Utf-8"), for example:

String name = Req.getparameter ("UserName");

String userName = new String (Name.getbytes ("iso-8859-1"), "Utf-8");

In this way, it is good to pass the Chinese characters correctly to the background data.

When using post to submit, it needs to be set to Req.setcharacterencoding ("Utf-8"), which is directly before the background data to pass the data before adding OK.

7.15 about resolving the get and post garbled problems of Javaweb background resolution Servlet

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.