1、写入的时候:
public boolean addCookie( HttpServletRequest req, HttpServletResponse resp){
//创建 Cookie cookie1 = null; try{ cookie1 = new Cookie("nickname",URLEncoder.encode(name,"utf-8")); cookie1.setPath("/"); cookie1.setMaxAge(1*60);// cookie记录60miao
//添加到response对象中
resp.addCookie(cookie1);
}catch(UnsupportedEncodingException e){
// TODO Auto-generated catch block e.printStackTrace();
return false; } return true; }
2、读取的时候:
URLDecoder.decode(cookie.getValue(), "UTF-8");