Questions about URL passing Chinese parameters in Java

Source: Internet
Author: User

Today, when invoking an interface, a Chinese parameter needs to be passed, resulting in no data being obtained because of the encoding problem of the Chinese-language parameter.

Source of the problem: URL url= new URL ("http://XXX?OrganName= Justice Department");

The present solution is as follows:

1. Encode the Chinese characters that you want to pass the URL to:

String message = Java.NET.URLEncoder.encode("Judicial Hall", "Utf-8");

2, in the URL to pass the Chinese page to decode the characters:

String msg = request.getparameter ("message");
String Str=new string (msg.getbytes ("iso-8859-1"), "UTF-8");

--------------------------------------------------------------------------------------

Note: Why to convert the character set form to UTF-8 form, because Iso-8859-1 is the standard character set used in the network transmission in Java, request.getparameter ("message"); Get the iso-8859-1 character set, so you have to convert it.

Questions about URL passing Chinese parameters in Java

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.