Persistent cookies from a servlet in IE

前端 未结 6 1722
故里飘歌
故里飘歌 2020-12-10 07:23

I have a cookie which is generated from a servlet and that I would like to be persistent - that is, set the cookie, close down IE, start it back up, and still be able to re

6条回答
  •  Happy的楠姐
    2020-12-10 07:56

    I had a similar issue with IE8 as well, except that the cookie was persisting when using http but not when using https. Intellectual Tortoise's solution worked for me, as I had '=' and other chars in there that were screwing it up. Before I encoded the https cookie, it showed as expiring at "End of session". After encoding the value, it expired with the maxAge I passed in. Here's the methods I used to encode/decode the cookie value before setting and after retrieving it:

    public static String encodeString(String s) {
        String encodedString = s;
    
        try{
            encodedString = URLEncoder.encode(s, "UTF-8");
        } catch (UnsupportedEncodingException e) {}
    
        return encodedString;
    }
    public static String decodeString(String s) {
        String decodedString = s;
    
        try{
            decodedString = URLDecoder.decode(s, "UTF-8");
        } catch (UnsupportedEncodingException e) {}
    
        return decodedString;
    }
    

提交回复
热议问题