A Servlet that Sets Two Cookies
public class SetCookies extends HttpServlet {
Random rand = new Random() ; // Seeded by current date/time
public void doGet(HttpServletRequest req,
HttpServletResponse resp) throws . . . {
resp.setContentType(“text/html”) ;
Cookie session = new Cookie(“mySessionCookie”,
resp.addCookie(session) ;
Cookie persistent = new Cookie(“myPersistentCookie”,
persistent.setMaxAge(3600) ; // One hour
resp.addCookie(persistent) ;
PrintWriter out = resp.getWriter() ;
out.println(“<html><head></head><body>”) ;
out.println(“<h1>Enjoy your cookies!</h1>”) ;
out.println(“</body></html>”) ;