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

public class session extends HttpServlet {
   public void doGet(HttpServletRequest req, HttpServletResponse res) 
   throws IOException, ServletException {
      HttpSession session = req.getSession(true);
      session.setMaxInactiveInterval(30);
      String name = (String)session.getAttribute("name");
      if(name == null) {
         name = req.getParameter("name");
         if(name == null) {
            res.setContentType("text/html");
            PrintWriter out = res.getWriter();
            out.println("<FORM METHOD=GET ACTION=/servlet/session>"
                        +"Name: <INPUT TYPE=TEXT NAME=name>"
                        +"<INPUT TYPE=SUBMIT>");
            out.flush();
         }
         else {
            session.setAttribute("name", name);
            res.sendRedirect("/servlet/session");
         }
      }
      else {
         res.setContentType("text/html");
         PrintWriter out = res.getWriter();
         out.println("<H1>Hello, " + name + "!</H1>");
         out.flush();
      }
   }
}