Cookie not removed :(

Discussion in 'Programming' started by spiderman3, Jan 9, 2010.

  1. #1
    my code to making cookie in jsp.

     Cookie cookie= new Cookie("iAdminName",iAdminName);
                      cookie.setMaxAge(-1);
                      response.addCookie(cookie);
    Code (markup):
    to remove cookie i use this

     Cookie killMyCookie = new Cookie("iAdminName", null);
                killMyCookie.setMaxAge(0);
                killMyCookie.setPath("/");
                response.addCookie(killMyCookie);
    Code (markup):
    problem is cookie is not removed, is there a bug in my coding?:confused:

    how i remove cookie?

    I worked on JSP & JAVA, this is the source code of JSP file.
     
    spiderman3, Jan 9, 2010 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    Why are you making another object, don't you need to use the same object?

    
     Cookie cookie= new Cookie("iAdminName",iAdminName);
                      cookie.setMaxAge(-1);
                      response.addCookie(cookie);
    
    cookie.setValue(null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    
    Code (markup):
     
    Kaizoku, Jan 10, 2010 IP
  3. CDarklock

    CDarklock Peon

    Messages:
    200
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My psychic powers tell me...

    ...your original cookie has a different path.

    I suspect he kills the cookie on a different page.
     
    CDarklock, Jan 11, 2010 IP
  4. ayushdeepsingh

    ayushdeepsingh Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    yea lolz as CDarklock said u saving cookie in diffrent path and deleteing cookie of diffrent path :p
    try this :
     Cookie killMyCookie = new Cookie("iAdminName", null);
                killMyCookie.setMaxAge(-0);
                killMyCookie.setPath(request.getHeader("host"));
                response.addCookie(killMyCookie);
    
    Code (markup):
     
    ayushdeepsingh, Jan 12, 2010 IP
  5. spiderman3

    spiderman3 Peon

    Messages:
    177
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes i removed the cookie in defferent page (Logout.jsp) and i create cookie in
    (Login.jsp).
     
    spiderman3, Jan 12, 2010 IP