Java - URLDecoder.decode(String s) vs URLDecoder.decode(String s, String enc)

£可爱£侵袭症+ 提交于 2019-12-13 18:05:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!