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

public class Kentat extends HttpServlet {
    static public int count = 0;

    public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {

	res.setContentType("text/html");
	PrintWriter out = res.getWriter();
	out.println("<html><head><title>Aika</title></head><body>");
	Cookie[] piparit = req.getCookies();
	if (piparit != null) {
	    for (int i = 0; i < piparit.length; i++) {
		out.println("Pipari " + piparit[i].getName() + " = "
			    + piparit[i].getValue() + "<br>");
	    }
	}
	out.println("Etunimi: " + req.getParameter("etu") + "<br>"
		    + "Sukunimi: " + req.getParameter("suku")
		    + "</body></html>");
	Cookie c = new Cookie("salaisuus", "hys hys " + count++);
	c.setMaxAge(120);
	res.addCookie(c);

	out.close();
    }


    public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req, res);
    }
}
