首页 > 代码库 > cookie存中文

cookie存中文

 

 1 cookie存取:
 2 存: Cookie cookie = new Cookie("title",URLEncoder.encode("标题","utf-8"))
 3          cookie.setMaxAge(365 * 24 * 60 * 60);
 4           response.addCookie(cookie);
 5 取: Cookie[] cookies = request.getCookies();
 6          Cookie sCookie = null;
 7          String cookievalue="";
 8          for(int i = 0; i < cookies.length; i++){
 9                 sCookie = cookies[i];
10                 if(sCookie.getName()!=null&&sCookie.getName().equals("title"))
11                           cookievalues=URLDecoder.decode(sCookie.getValue(),"utf-8");
12          }