I want to update the value of an existing cookie, and I'm having problems. Here is my code:
// Get all the cookies
Cookie [] cookies = request.getCookies();
boolean foundCookie1 = false;
// If there are cookies (to avoid null pointer exception)
if (cookies != null)
{
// Loop through all the cookies to find the right one
for (int index = 0; index < cookies.length; index ++)
{
Cookie cookie1 = cookies[index];
// If the hostname cookie is there
if (cookie1.getName().equals("hostname")
{
foundCookie1 = true;
empname = cookie1.getValue();
out.println("value in cookie before update: " + empname);
String hostnameForCookie = request.getParameter("hostnameforCookie"
cookie1.setValue(hostnameForCookie);
}
}
}
My variable "hostnameForCookie" is accurate, because I can output it to the screen.
I am also able to get the value currently in the cookie (before I attempt to update it) so I know I'm accessing the cookie too.
So I can get the value in the cookie, just not update it.
Can someone please help me out? I have been trying to figure this out for days and it's driving me bonkers!!
Thanks a mill!
Rachel
// Get all the cookies
Cookie [] cookies = request.getCookies();
boolean foundCookie1 = false;
// If there are cookies (to avoid null pointer exception)
if (cookies != null)
{
// Loop through all the cookies to find the right one
for (int index = 0; index < cookies.length; index ++)
{
Cookie cookie1 = cookies[index];
// If the hostname cookie is there
if (cookie1.getName().equals("hostname")
{
foundCookie1 = true;
empname = cookie1.getValue();
out.println("value in cookie before update: " + empname);
String hostnameForCookie = request.getParameter("hostnameforCookie"
cookie1.setValue(hostnameForCookie);
}
}
}
My variable "hostnameForCookie" is accurate, because I can output it to the screen.
I am also able to get the value currently in the cookie (before I attempt to update it) so I know I'm accessing the cookie too.
So I can get the value in the cookie, just not update it.
Can someone please help me out? I have been trying to figure this out for days and it's driving me bonkers!!
Thanks a mill!
Rachel