如何用Cookie存储中文信息?
时间:2006-08-03 来源:chen_bo
写Cookie:
Cookie chineseCookie = new Cookie("chineseCookie", URLEncoder.encode("中文", "UTF-8"));
chineseCookie.setMaxAge(36000);
response.setCharacterEncoding("UTF-8");
response.addCookie(chineseCookie);
读Cookie:
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
if ("chineseCookie".equals(cookies[i].getName())) {
String temp = cookies[i].getValue();
temp = URLDecoder.decode(temp, "UTF-8");
System.out.println("chineseCookie : " + temp); //测试打印语句
}
}
Cookie chineseCookie = new Cookie("chineseCookie", URLEncoder.encode("中文", "UTF-8"));
chineseCookie.setMaxAge(36000);
response.setCharacterEncoding("UTF-8");
response.addCookie(chineseCookie);
读Cookie:
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
if ("chineseCookie".equals(cookies[i].getName())) {
String temp = cookies[i].getValue();
temp = URLDecoder.decode(temp, "UTF-8");
System.out.println("chineseCookie : " + temp); //测试打印语句
}
}
相关阅读 更多 +