Cookie里不能保存中文,用UrlEncode编码一下

解决方案 »

  1.   

    不能用中文啊,用urlEncode如何写呢
      

  2.   

    问题:存到Cookie时用URLEncoder.encode("中文",   "UTF-8"),但取出来时按"UTF-8"进行转码却不行(ISO-8859-1也不行),什么原因呢?  写Cookie:   
              Cookie   chineseCookie   =   new   Cookie("chineseCookie",   URLEncoder.encode("中文",   "UTF-8"));   
              chineseCookie.setMaxAge(36000);   
              response.setCharacterEncoding("UTF-8");   
              response.addCookie(chineseCookie);   
        
      读Cookie:   
              Cookie[]   cookies   =   request.getCookies();   
              for   (int   i   =   0;   i   <   cookies.length;   i++)   {   
                      if   ("chineseCookie".equals(cookies[i].getName()))   {   
                              String   temp   =   cookies[i].getValue();   
                              temp   =   URLDecoder.decode(temp,   "UTF-8");   
                              System.out.println("chineseCookie   :   "   +   temp);         //测试打印语句   
                      }   
      

  3.   

    // write
    HttpCookies cookie = new HttpCookies("MyCookieName");
    cookie.Value = Server.UrlEncode("王二");
    Response.Cookies.Add(cookie);// read
    HttpCookies cookie = Request.Cookies["MyCookieName"];
    string myName = Server.UrlDecode(cookie.Value);
      

  4.   

    我的多值Cookie,Cookie名不是中文的,值是中文的
      

  5.   

    If Request.Cookies("yj_user") IsNot Nothing Then
                Dim cookie As HttpCookie = Request.Cookies("yj_user")            txtMan.Text = cookie.Values("username").ToString
                txtTel.Text = cookie.Values("userTel").ToString
                txtMail.Text = cookie.Values("useremail").ToString
                txtqq.Text = cookie.Values("userqq").ToString
                txtfb.Text = cookie.Values("userid").ToString '加入发布人id            Panel1.Visible = True
            Else
                Panel1.Visible = False
            End If