Question about URL encoding in java.net (encode, decode)

Source: Internet
Author: User

For the encoding in the URL, we can use these two functions for processing:

Java.net. urlencoder. encode (STR, "utf8 ");

Java.net. urldecoder. Decode ("% E4 % B8 % 8d % E5 % ad % 95", "UTF-8 ");

These two functions encode and decode the URL respectively. They always think that any encoding will be the same string containing a lot of % numbers after URL transcoding, and then write an instance, only when you know that you are mentally handicapped;

We can encode the code into UTF-8, GBK, iso-8859-1 and other formats of URL code; that is:

Java.net. urlencoder. encode (STR, "utf8 ");

 

When we perform reverse transcoding, we must know the encoding format containing the "%" sign, and then pass this parameter to decode; that is:

Java.net. urldecoder. Decode ("% E4 % B8 % 8d % E5 % ad % 95", "UTF-8 ");

 

 

 

This is a lesson for me, but I can understand it. Mark it in the log;

Related Article

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.