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