Transcoding and decoding of parameters after URL
Import Java.net.urldecoder;import Java.net.URLEncoder;
" =abc?%1&2<3,4> " "UTF-8"); System. out = 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>
Description of JDK:
string Java.net.URLEncoder.encode (string s, String enc) throws Unsupportedencodingexceptiontranslates astringinto application/x-www-form-urlencoded formatusingA specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafecharacters. Note:the World Wide Web Consortium recommendation states that UTF-8should be used. Not doing so may introduce incompatibilites. Parameters:s String to is translated. Enc the name of a supported character encoding. Returns:the translated String. Throws:unsupportedencodingexception-If The named encoding isNot supported Since:1.4See Also:URLDecoder.decode (java.lang.String, java.lang.String) String Java.net.URLDecoder.decode (string s, Strin G enc) throws unsupportedencodingexceptiondecodes a application/x-www-form-urlencodedstring usingA specific encoding scheme. The supplied encoding isUsed to determine what characters is represented by any consecutive sequences of the form"%xy". Note:the World Wide Web Consortium recommendation states that UTF-8should be used. Not doing so may introduce incompatibilites. Parameters:s the String to decode enc the name of a supported character encoding. Returns:the newly decoded String throws:unsupportedencodingexception-If character encoding needs to being consulted, but named character encoding isNot supported Since:1.4See Also:URLEncoder.encode (java.lang.String, java.lang.String)
transcoding and decoding of URL parameters using Urlencoder, Urldecoder