Thread: cookie

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0

    Question cookie


    if I define method:

    public boolean putCookie(HttpServletRequest req, HttpServletResponse resp
    , String name, String value
    ) {
    Cookie c = new Cookie(name, value);
    c.setMaxAge(3600);
    c.setDomain("www.office.com");
    resp.addCookie(c);
    return true;
    }

    what must be method getCookie?
  2. #2
  3. No Profile Picture
    Java Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    5
    Rep Power
    0
    How about...

    public String getCookie(HttpServletRequest req, String name){
    Cookie [] cookies = req.getCookies();
    for (int i=0;i<cookies.length;i++){
    if (cookies[i].getName().equals(name)) return cookies[i].getValue();
    }
    return null;
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0
    This method will not find mine cookie in domain "www.office.com". How to me to set the domain for reception cookie?
  6. #4
  7. No Profile Picture
    Java Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    5
    Rep Power
    0
    Not sure about your question...can you be more specific. What I can tell you though is that the cookies have to be set on the same domain that you are reading them from or they will not be readable

IMN logo majestic logo threadwatch logo seochat tools logo