首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-11-23 
jsp写入cookie中文出现乱码的解决办法第一步:写入cookie时先进行编码??????????? Cookie cookienew Cooki

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 }"/>

热点排行