汉字经常会有这样的问题,我用笨办法,把汉字编码后存储,用的时候再解码
参考 java.net.URLEncoder 和 java.net.URLDecoder 这两个类看看吧。
=========== Sorce ============
<%@ page contentType="text/html; charset=gb2312"%>
取得Cookie的信息<%
String str1="张小忠"+(new java.util.Date()).toString();
String str =new String(str1.getBytes("iso8859-1"));
//Cookie user1=new Cookie("id1",str);
Cookie user1=new Cookie("id1",java.net.URLEncoder.encode(str1,"gb2312"));
Cookie user2=new Cookie("id2","asf");
response.addCookie(user1);
response.addCookie(user2);
%>
<%
Cookie[] allcookie=request.getCookies();
for(int i=0;i
{
String idx=allcookie[i].getName();
String value=allcookie[i].getValue();
out.print(idx+":");
value = java.net.URLDecoder.decode(value,"gb2312");
out.print(value+"
");
}
%>
============ End ==========