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

StackOverflow https://stackoverflow.com/questions/21309930

  •  01-10-2022
  •  | 
  •  

Pergunta

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 retrieving 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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top