cookie在后台的存取
/************存***********/
//获取cookie值
String cookieValue = "";
Cookie[] cookies = request.getCookies();
if (cookies != null) { //防止出现nullpoint错误
for (Cookie cookie : cookies) {
if (cookie.getName().equals("myCookie")) {
cookieValue = cookie.getValue();
}
}
}
//更新cookie的值(id为新的存储到cookie里面的值)
cookieValue = cookieValue + id.toString() + "%";
Cookie userCookie = new Cookie("myCookie", cookieValue);
userCookie.setMaxAge(30 * 24 * 60 * 60); //存活期为一个月 30*24*60*60
userCookie.setPath("/");
response.addCookie(userCookie);
/************存***********/
/************取***********/
//再次获取cookie的值
//此处已经获取到存在cookie中的id值,现拆分并从数据库中查询对应对象的集合
String[] cookId = cookieValue.substring(0, cookieValue.length() - 1).split("%");
/************取***********/
controller参数里面需要HttpServletResponse response、HttpServletRequest request
response存,request取