问题
What is the difference between
URLDecoder.decode(String s)
and
URLDecoder.decode(String s, String enc)
I had a Cookie value like
val=%22myvalue%22
I am retirieving it.
Cookie[] cookies=request.getCookies();
String val=cookies[0].getValue();
But the value of val is %22myvalue%22
So I tried URLDecoder
String val1=URLDecoder.decode(val);
String val2=URLDecoder.decode(val,"utf8");
And values of both are same, that is myvalue
So what is the difference between both?
回答1:
URLDecoder.decode(String s)
Decodes a x-www-form-urlencoded string. The platform's default encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".
Note: It is deprecated.
URLDecoder.decode(String s, String enc)
Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".
Entire info you can find here.
来源:https://stackoverflow.com/questions/21309930/java-urldecoder-decodestring-s-vs-urldecoder-decodestring-s-string-enc