import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;

// This page just generates a very simple order form, which calls
// a servlet to handle the order and add to the shopping cart.
// Normally, we would genertate this from a database.

// Note that we need to do this as a servlet to make sure that
// the session will be preserved even if URL rewriting used.

public class FormServlet extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) 
                    throws ServletException, IOException {
 
    PrintWriter out = response.getWriter();

    out.println("<HTML><BODY><H3>ACME Order Form</H3>");
    out.println("<FORM METHOD=POST ACTION='");

    // The response.encodeURL adds the session ID to the path if
    // cookies cannot be used.

    out.println(response.encodeURL("http://localhost:8080/session/Shop") + "'>");

    out.println("Item name: <INPUT TYPE=TEXT SIZE=20 NAME='item'><BR>");
    out.println("Quantity: <INPUT TYPE=TEXT SIZE=5 NAME='quantity'><BR>");

    out.println("<INPUT TYPE=SUBMIT VALUE='Order Item'>");
    out.println("</FORM></BODY></HTML>");

    }
  }
