存儲Cookie
for(String str:books){
str=new String(str.getBytes("ISO-8859-1"),"utf-8");
str=URLEncoder.encode(str); 解決Cookie存中文的亂碼問題
Cookie cook=new Cookie("books",str); 創建Cookie對象
response.addCookie(cook); 使用response對象的addCookie()的方法寫入 cook
}
讀取Cookie
Cookie[] cooks=request.getCookies(); 用過request兌現創建一個Cookie的數組
String value="";
for(int i=0;i<cooks.length;i++){
if(cooks[i].getName().equals("books")){
value=new String(value.getBytes("ISO-8859-1"),"utf-8");
value=URLDecoder.decode(cooks[i].getValue(), "GB2312"); 解決Cookie讀取中文的亂碼問題
out.print(value);
}
}