How to add data to a cookie

I want to add two values ​​to the cookie and get them. I do this, but I get only the first value, not the second.

Cookie c = new Cookie("a", a);
c.setMaxAge(60);
response.addCookie(c);

Cookie b = new Cookie("d", d);
b.setMaxAge(5 * 60);
response.addCookie(b);

When reading:

Cookie cookies[] = getRequest().getCookies();
Cookie myCookie = null;
if (cookies != null) {      
    for (int i = 0; i < cookies.length; i++) {
        log.info("test ;;;"+cookies[i].getName());
    }
}

This returns only one information.

+3
source share
4 answers

, . cookie , . , , , , (, , cookie), cookie. , (, JSP).

/ / , . FireFox Firebug ( Firebug, Net, , , /, cookie).

+2

- :

for(int i= 0; i < cookies.length; i++) { 
   Cookie cookie = cookies[i];
   log.info("name: "  + cookie.getName()) 
   log.info("value: " + cookie.getValue()) 
}

cookie. , , cookie . , cookie .

0

- ,

response.addCookie( Cookie ( "", "" )); response.addCookie( Cookie ( "pwd", "sunnymehta" ));

Cookie [] cookie = request.getCookies(); (Cookie ck: cookie) {  System.out.println(ck.getName()); }

0

cookie, . , , - , , cookie, - cookie - . http://www.quirksmode.org/js/cookies.html , cookie. ( , -, cookie, , .)

I understand that your java calls should write a file formatted in a formatted cookie and create a valid array of cookies for you. But the fact that you get one object back seems suspicious to me in the light of the basic cookie data format.

In the past, I used Cookie Pal to check raw cookies, although the site mentions IE6 support, so I think it's a bit outdated.

0
source

Source: https://habr.com/ru/post/1729221/


All Articles