cookie中存在中文问题,参照下面的代码,可以有些收获:
写入cookie的是时候:
//通过表单获得的
String userName = new String(request.getParemeter("userName").getBytes("iso-8859-1"),"gb2312");
try{
//按照gb2312的编码方式写入cookie
userName = URLEncoder.encode(userName,"gb2312");
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}
Cookie c = new Cookie("userName",userName);
从cookie中读出:
try{
value = URLDecoder.decode(cookie.getValue(),"gb2312");
}catch(UnsupportedEncoddingException e){
e.printStackTrace();
}
return value; |