import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Servlet that keeps count of the number of visits * to a site using a cookie. */ public class CookieCounter extends HttpServlet { private static final int oneYear = 60*60*24*365; public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get count from cookie if available, otherwise // use initial value. int count = 0; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i=0; (i \n" + " \n" + " \n" + " \n" + " CookieCounter.java \n" + " \n" + " \n" + " \n" + "

You have visited this page " + count + " time(s) \n" + " in the past year, or since clearing your cookies.

\n" + " \n" + "" ); servletOut.close(); } }