import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class cookie extends HttpServlet {
   public void service(HttpServletRequest req, HttpServletResponse res)
   throws IOException, ServletException {
      Cookie cookie = new Cookie("Matthew", "Coan");
      res.addCookie(cookie);
      cookie = new Cookie("Matthew2", "Coan2");
      cookie.setComment("Test");
      cookie.setDomain("127.0.0.1");
      cookie.setPath("/");
      cookie.setVersion(1);
      cookie.setMaxAge(60 * 60 * 24 * 365 * 30);
      res.addCookie(cookie);
      res.setContentType("text/plain");
      Cookie cookieArray[] = req.getCookies();
      PrintWriter out = res.getWriter();
      if(cookieArray != null) {
         for(int i = 0; i < cookieArray.length; i++) {
            cookie = cookieArray[i];
            out.println("name="+cookie.getName());
            out.println("value="+cookie.getValue());
            out.println("comment="+cookie.getComment());
            out.println("domain="+cookie.getDomain());
            out.println("secure="+cookie.getSecure());
            out.println("maxage="+cookie.getMaxAge());
            out.println("path="+cookie.getPath());
            out.println();
         }
      }
      else
         out.println("NO COOKIES!");
      out.flush();
   }
}