Cookie cookie = new Cookie("userId", "28764"); //Creating new Cookie
response.addCookie (cookie); // sending cookie to the browser
// Printing out all Cookies
Cookie[] cookies = request.getCookies();
if (cookies != null)
{
for (int i=0; i
String name = cookies[i].getName();
String value = cookies[i].getValue();
}
}
Note : If you want to save special characters like "=", or spaces, in the value of the cookie, then makesure you URL encode the value of the cookie , before creating a cookie.
No comments:
Post a Comment