Reputation: 2579
I had a GWT servelt on whose doGet method, I created a cookie as shown below:
Cookie nameCookie = new Cookie("name","adam");
response.addCookie(nameCookie);
I tried to read this on the client side as
String name = Cookies.getCookie("name");
But the output of string variable name was coming out as undefined.
Upvotes: 1
Views: 229
Reputation: 2579
I solved it by finding out that while creating a cookie, you also have to set the path for it. So in the server side,
Cookie nameCookie = new Cookie("name","adam");
nameCookie.setPath("/");
response.addCookie(nameCookie);
Now the following client side code returns the proper value as adam
String name = Cookies.getCookie("name");
Upvotes: 2