Java Reference
In-Depth Information
Figure 3.12
The
SayHello
servlet with links to allow users to purchase food
Figure 3.13
The
BuyFood
servlet prompts customers to fill in their name and how much food they'd
like to buy.
The
HTML
for the
GET
method of the
BuyFood
servlet is a standard
HTML
form:
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String foodName = request.getParameter("foodName");
PrintWriter html = response.getWriter();
html.append("<html>");
html.append("<body>");
html.append("You would like to buy " + foodName);
html.append("<form method=post action="BuyFood">");
html.append("Customer name:");
html.append("<input type=text name=customerName> <br/>");
html.append("How many would you like to buy?");
html.append("<input type=text name=quantity><br/>");
html.append("<input type=hidden name=foodName value=""
