import javax.servlet.*; 
import javax.servlet.http.*; 
import java.util.*; 
import java.io.*; 
 
/** 
 * a Java servlet that leads to St10Sessions2.jsp
 *
 * @author Sharon Tuttle
 * @version 4-3-13
 */

public class St10ServletToJsp extends HttpServlet 
{ 
    /**
     * create an HTML document that calls St10Sessions2.jsp
     *     when its submit button is clicked.
     * 
     * @param request object containing the GET request information
     *                from the browser 
     * @param response object containing the response that will
     *                 be sent back to the browser - here containing
     *                 a form with the st10_sessions2.jsp as its
     *                 action
     */

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
                     throws ServletException, IOException
    {
        HttpSession session = request.getSession(true);

        String sessionId = session.getId();

        response.setContentType("text/html");
        
        ServletOutputStream getOut = response.getOutputStream();

        String title = "St10ServletToJsp in-class";

        Html318Helpers.beginHtml(getOut, title);

        getOut.println("    <h1> St10ServletToJsp </h1>");

        getOut.println("");
        getOut.println("    <ul>");
        getOut.println("        <li> is the automatically-defined " +
                       "session new?: ");
        getOut.println(session.isNew() + " </li>");

        getOut.println("        <li> trying to set an attribute for " +
                       "this session:");
        getOut.println("             attribute page_num, value 1;");
        session.setAttribute("page_num",  new Integer(1));

        getOut.println("             </li>");
        getOut.println("        <li> max inactive interval: ");
        getOut.println(session.getMaxInactiveInterval() + " </li>");
        getOut.println("    </ul>");

        getOut.println("");
        getOut.println("    <form action=");
        getOut.println("     \"http://nrs-projects.humboldt.edu:8888/examples" +
                       "/jsp/student/St10Sessions2.jsp\"");
        getOut.println("          method=\"post\">");
        getOut.println("        <table>");
        getOut.println("        <tr> <td> Name: </td> ");
        getOut.println("             <td> <input type=\"text\" name=\"" +
                       "username\" /> </td>");
        getOut.println("        </tr>");
        getOut.println("        </table>");
        getOut.println("        <p>");
        getOut.println("            <input type=\"submit\" value=\"Submit\"" +
                       " />");
        getOut.println("        </p>");
        getOut.println("    </form>");
        getOut.println("");

        Html318Helpers.endHtml(getOut);
    }
}