当前位置: 代码迷 >> JavaScript >> jsp写入cookie中文出现乱码有关问题,history.go(-1) 或 history.back() 网页已过期 解决方法
  详细解决方案

jsp写入cookie中文出现乱码有关问题,history.go(-1) 或 history.back() 网页已过期 解决方法

热度:760   发布时间:2012-09-17 12:06:51.0
jsp写入cookie中文出现乱码问题,history.go(-1) 或 history.back() 网页已过期 解决办法
第一步:写入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 }"/>



使用javascript的history.back()进行返回时,有时会提示“网页已过期”,多数是因为目标页面的form为post提交方式,而且是表单已经提交后的响应页面,无法找到form中的具体参数,而“报错”,具体解决办法:



一、在要返回的目标页面中,添加<%response.setHeader("cache-control","public"); %>



二、将目标页面的form的method="post"去掉,或改为method="get"。
  相关解决方案