存进去的语句是
Cookie chineseCookie = new Cookie("chineseCookie", URLEncoder.encode("中文", "UTF-8"));
chineseCookie.setMaxAge(36000);
response.setCharacterEncoding("UTF-8");
response.addCookie(chineseCookie);
读Cookie的语句是
String temp = new String(cookies[i].getValue().getBytes("ISO-8859-1"));
Cookie chineseCookie = new Cookie("chineseCookie", URLEncoder.encode("中文", "UTF-8"));
chineseCookie.setMaxAge(36000);
response.setCharacterEncoding("UTF-8");
response.addCookie(chineseCookie);
读Cookie的语句是
String temp = new String(cookies[i].getValue().getBytes("ISO-8859-1"));
解决方案 »
- 跳到JSP页面时 为什么会报其他类的错?在线等
- JSP用MVC时提示bean bvo not found within scope
- 请教高手问题,关于js+servlet,灰常感谢啦!
- 求一个简单的问题,大家帮帮忙
- 实现Grails应用中的邮件异步发送
- 窗体间传值,在线待求解
- 请问怎样用javabean封装连接mySQL数据库?
- 固定ip有多大可能?
- 请问如何将一个Action中的ArrayList传到JSP中?用struts
- 如何在tomcat4。1上让自己的servlet运行?急急急啊(在线等待)
- 请问jsp中为什么要用到<%@ include file="*.inc"%>这个.inc到底是什么文件
- 100分求解!!!!!!
读cookie的语句是
String temp = new String(cookies[i].getValue().getBytes("UTF-8"));但读出来的是:%E4%B8%AD%E6%96%87,和写在cookie中的是一模一样的字串
现将完整的代码列出,也好给碰到类似问题的朋友参考参考:
写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); //测试打印语句
}
}