FileDocCategorySizeDatePackage
CookieServlet.javaAPI DocExample1206Sat Mar 15 19:39:50 GMT 2003com.oreilly.javaxp.cactus.servlet

CookieServlet

public class CookieServlet extends HttpServlet
author
Brian M. Coyner $version $Id: CookieServlet.java,v 1.4 2003/02/27 00:24:43 jepc Exp $

Fields Summary
public static final String
TEST_COOKIE_NAME
Constructors Summary
Methods Summary
protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)


         
              

        Cookie cookie = getCookie(req);
        int count = Integer.parseInt(cookie.getValue());
        count++;
        cookie.setValue(String.valueOf(count));
        res.addCookie(cookie);
    
protected javax.servlet.http.CookiegetCookie(javax.servlet.http.HttpServletRequest req)

        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                if (TEST_COOKIE_NAME.equals(cookies[i].getName())) {
                    return cookies[i];
                }
            }
        }

        return new Cookie(TEST_COOKIE_NAME, "0");