日期:2014-05-16  浏览次数:20371 次

jsp写入cookie中文出现乱码的解决办法

第一步写入cookie时先进行编码

??????????? Cookie cookie=new Cookie("groupMembersList",URLEncoder.encode? (groupMembersList,"GBK"));???????????????????????????????????????? //默认为临时Cookie,MaxAge<0
??????? ?//cookie.setMaxAge(-1);
??????? response.addCookie(cookie);

?

第二步:读取cookie再进行解码

?????? <%
??????????? ?Cookie[] cookies=request.getCookies();
??????????? ?for(Cookie cookie:cookies){
?????????????????? ?if(cookie.getName().equalsIgnoreCase("groupMembersList"))
?????????? ??request.setAttribute("group",URLDecoder.decode(cookie.getValue(),"GBK"));???
????????? ??}
????? %>

???? <c:out value="${requestScope.group }"/>