transcoding and decoding of URL parameters using Urlencoder, Urldecoder

Source: Internet
Author: User

transcoding and decoding of URL parameters

Import Java.net.URLDecoder; Import  = "=abc%1&2<3,4>"= Urlencoder.encode (strtest, "UTF-8"= Urldecoder.decode ( Strtest, "UTF-8"); System.out.println (strtest);

Execution Result:

%3f%3dabc%3f%e4%b8%ad%251%262%3c3%2c4%3e
=abc?%1&2<3,4>

1. The problem arises

In restful service design, when querying some information, the general URL address is designed as: Get/basic/service? Keyword= history, and the like URL address. However, in the actual development and use, there is a garbled situation, in the background read keyword information is garbled, can not be read correctly.

2. How are garbled characters generated?

Because we use URLs to pass parameters this way is dependent on the browser environment, that is, the URL and the URL contained in the various Key=value format of the pass parameter key value pair parameters are processed in the browser address bar in the processing principle of the corresponding encoding passed to the background for decoding. Since we do not have any processing, when the JavaScript request URL and the argument exists in Chinese (that is, input box input in Chinese), the URL of the Chinese language parameters are encoded according to the browser mechanism. Encoding has a garbled problem at this time.

transcoding and decoding of URL parameters using Urlencoder, Urldecoder

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.