日期:2014-05-17 浏览次数:21060 次
ProductDAO 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); }
DoText dt = new DoText(); ProductDAO 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]; cookieValue = myCookie.getValue(); out.print(cookieValue); break; } } }