response.addCookie() can make the browser take 2 cookie with the samename???

Discussion in 'Java' started by lightning, Apr 2, 2008.

  1. lightning

    lightning Guest

    I put some encrypted token in the cookie, and I set a expiration of
    half an hour .

    In order to avoid the cookie dies and the user get automately logged
    out,

    I use reponse.addCookie() to reset the cookie's expiration to half an
    hour .

    the code I use is just like below:

    public long getId(String name) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
    for (Cookie i : cookies) {
    if (i.getName().equals(name)) {
    i.setMaxAge(ConfigServlet.cookie_expire);
    response.addCookie(i);
    return MagicUtil.getIdFromMagicNo(i.getValue());
    }
    }
    }
    return -1l;
    }

    But I found that my browser IE6 send 5 cookie back to me, two pair has
    the same name.


    Cookie: magicno=-6568942197980035062.59357; magicinfo=MDYgNyskKCB/
    ISEh; JSESSIONID=5C771E6A3CC321D842A7344BE49C2A81;
    magicno=-6568942197980035062.59357; magicinfo=MDYgNyskKCB/ISEh

    Is this because IE6 sucks or what I do is not right?
     
    lightning, Apr 2, 2008
    #1
    1. Advertising

  2. Re: response.addCookie() can make the browser take 2 cookie with thesame name???

    I hope you know that you should just use an HttpSession and not worry
    about that. With HttpSession you can set a time limit.
     
    Chase Preuninger, Apr 3, 2008
    #2
    1. Advertising

  3. lightning

    lightning Guest

    Re: response.addCookie() can make the browser take 2 cookie with thesame name???

    I need a scalable design,maybe this web module will be deployed in a
    whole tomcat farm,every tomcat has the same job ,a load balancer is at
    the front,any one tomcat dies can not affect the service, so I must
    not use a session.

    On 4ÔÂ3ÈÕ, ÉÏÎç8ʱ27·Ö, Chase Preuninger <> wrote:
    > I hope you know that you should just use an HttpSession and not worry
    > about that. With HttpSession you can set a time limit.
     
    lightning, Apr 3, 2008
    #3
  4. lightning

    Lew Guest

    Re: response.addCookie() can make the browser take 2 cookie withthe same name???

    lightning wrote:
    > I need a scalable design,maybe this web module will be deployed in a
    > whole tomcat farm,every tomcat has the same job ,a load balancer is at
    > the front,any one tomcat dies can not affect the service, so I must
    > not use a session.


    (Please do not top-post.)

    Actually, load-balancing and clustering do not militate against the use of
    sessions. They do require that session-scoped objects be Serializable, at
    least on such systems that I've worked on.

    --
    Lew
     
    Lew, Apr 3, 2008
    #4
  5. lightning

    lightning Guest

    Re: response.addCookie() can make the browser take 2 cookie with thesame name???

    On 4ÔÂ3ÈÕ, ÉÏÎç11ʱ52·Ö, Lew <> wrote:
    > lightning wrote:
    > > I need a scalable design,maybe this web module will be deployed in a
    > > whole tomcat farm,every tomcat has the same job ,a load balancer is at
    > > the front,any one tomcat dies can not affect the service, so I must
    > > not use a session.

    >
    > (Please do not top-post.)
    >
    > Actually, load-balancing and clustering do not militate against the use of
    > sessions. They do require that session-scoped objects be Serializable, at
    > least on such systems that I've worked on.
    >
    > --
    > Lew



    Oh,finally,I worked it out.

    To delete that very cookie,not only the cookie name should be the
    same,but also the path should!

    I modified mycode:

    public void destory() {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
    for (Cookie i : cookies) {
    i.setPath("/"); // I added this line,because it's "/" when
    set
    i.setMaxAge(0);
    response.addCookie(i);
    }
    }
    }


    The cookie was desctoyed, also if I ensure these two key is the same,I
    can reset the time correctly!
     
    lightning, Apr 3, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    3
    Views:
    5,891
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. ad
    Replies:
    2
    Views:
    7,564
    Kevin Spencer
    Jan 27, 2006
  3. Peng Yu
    Replies:
    4
    Views:
    361
    peter koch
    Sep 20, 2008
  4. Replies:
    0
    Views:
    173
  5. PerlFAQ Server
    Replies:
    0
    Views:
    120
    PerlFAQ Server
    Feb 4, 2011
Loading...

Share This Page