0

When I am setting the cookie through JSP using the below code:

String username = userinfoid;
Cookie testcoo  = new Cookie ("username",username);

it is setting the cookie with value "zahidansari" (note value is with double quotes). Although value is correct it is bounded inside double quotes.

However when I am setting the cookie using the below code:

Cookie testcoo  = new Cookie ("username",username);

It is setting the cookie without the quotes.

I want the cookie value to be without the quotes. Does anybody have any idea why this is happening.

antnewbee
  • 1,779
  • 4
  • 25
  • 38

1 Answers1

1

Just got the same problem. Not to leave this question unanswered :) this is my workaround:

Encode cookie value:

String username = userinfoid;
Cookie testcoo  = new Cookie ("username", URLEncoder.encode(username, "UTF-8"));

For more information take a look other SO question

Community
  • 1
  • 1
alsid
  • 490
  • 6
  • 14