开发者

JSP cookies[loop].getValue() breaking when @ is a vaule

开发者 https://www.devze.com 2023-04-06 08:46 出处:网络
I have set a cookie to an email address for a low level login. When i get the value of the cookie it does not return anything past the @ sign?

I have set a cookie to an email address for a low level login. When i get the value of the cookie it does not return anything past the @ sign?

For example :

cookie value = 'name@domain.com'

cookie get value = 'variable = cookies[loop].getValue()'

Returns = 'name'

Any ideas on how 开发者_JAVA百科to solve this?

Possibly escape the characters?


The @ is an invalid character in a cookie. I suggest to URL-encode and URL-decode the cookie value.

Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));
// ...

and

String value = URLDecoder.decode(cookie.getValue(), "UTF-8");
// ...


Declaration of cookie

enter code here
   String str="name@domain.com";
    str=URLEncoder.encode(str);
    Cookie ck2=new Cookie("email",str);

===============================================================

    String a = URLDecoder.decode(cks[i].getValue());

this will get you cookie all characters including @, after@

0

精彩评论

暂无评论...
验证码 换一张
取 消