开发者

Why is cookie value part after '@' being ignored?

When I'm reading the value of a cookie, the part after '@' is being ignored. So, if my cookie value was "abc@xyz", I'm just getting "abc" when I'm retrieving value by

  Cookie cookies [] = request.getCooki开发者_StackOverflowes ();
    pwd=cookies[0].getValue();

whereas, in javascript I'm able to easily read it as "abc@xyz" and even in browser cookies, I can see the value of cookie to be "abc@xyz". What could be wrong here?


My first guess would be a problem related to character encoding. Have you tried to urlencode and -decode the cookie value?

EDIT:

You would retrieve the cookie value by using URLDecoder.decode (cookies[0].getValue(), "utf-8").

In order for that to work, the value must of course be encoded in the first place: Use URLEncoder.encode("abc@xyz", "utf-8"), if you're setting the cookie value from Java, or encodeURIComponent("abc@xyz") to set the value from JavaScript. I don't know how the cookie is set, so you might have to figure this one out for whatever platform you're working on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜