Thread: java/cookies

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    21
    Rep Power
    0

    java/cookies


    I am looking for some way to set up a code that will install a cookie on a user's system that will store any and all information they have entered in a form, so that next time they come to the page the fields will already have their information entered.

    I have looked all over for any kind of documentation on cookies, and I can only find things on tracking users and such. I know it is possible because the Ikonboard on my site does it, I've tried sifting through the code to figure it out, but it is all too far over my head.

    I found a javascript here in the "Clip Scripts" that appears to do what I want it to, but for some reason when I click on the link I just get a page full of code rather than the html page. I tried sifting through all the jumbled code to make sense of the java, but I can't get it to work. Plus, the script was copyrighted in 1996, and only talks about Netscape (barf).

    Any help in the right direction would be greatly appreciated. Just any help on cookies in general...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    68
    Rep Power
    14

    cookies


    not sure if this is what you want.....

    these are the methods or whatever you put in your servlet (at least this is what i use)
    ---------

    public boolean putCookie(HttpServletRequest req, HttpServletResponse resp
    , String name, String value
    ) {
    Cookie c = new Cookie(name, value);
    c.setMaxAge(put an integer in here for second or a zero for it to die when browser is closed);
    resp.addCookie(c);
    return true;
    }

    public String getCookie(HttpServletRequest req, HttpServletResponse resp
    , String name
    ) {
    Cookie[] cookies = req.getCookies();
    String ret = null;
    for (int i = 0; i < cookies.length; i ++) {
    if (cookies[i].getName().equals(name)) {
    ret = cookies[i].getValue();
    break;
    }
    }
    return ret;
    }




    these lines are examples of how i get and put cookies....
    --------------

    String login = getCookie(req, resp, "login");
    String password = getCookie(req, resp, "password");

    putCookie(req, resp, "login", user);
    putCookie(req, resp, "password", pass);

IMN logo majestic logo threadwatch logo seochat tools logo