java cookie 获取不到,为什么设置了cookie却获取不到值解决方案

HTML codeProductDAO pd = new ProductDAO();

String cookieName = "product";

String cookieValue = "";

Cookie[] cookies = request.getCookies();

Cookie myCookie = null;

if (null != cookies) {

for (int k = 0; k < cookies.length; k++) {

if (cookies[k].getName().equals(cookieName)) {

myCookie = cookies[k];

break;

}

}

}

if (myCookie != null) {

cookieValue = myCookie.getValue();

String[] aryStr = cookieValue.split(",");

boolean aryFlag = false;

for (int k = 0; k < aryStr.length; k++) {

if (aryStr[k].equals(pid)) {

aryFlag = true;

}

}

if (aryFlag == false) {

cookieValue += pid + ",";

Cookie cookie1 = new Cookie(cookieName, cookieValue);

cookie1.setMaxAge(365 * 24 * 3600);

cookie1.setPath("/");

response.addCookie(cookie1);

}

} else {

cookieValue = "," + pid + ",";

Cookie cookie1 = new Cookie(cookieName, cookieValue);

cookie1.setPath("/");

cookie1.setMaxAge(365 * 24 * 3600);

response.addCookie(cookie1);

}