Snack-Vending Machine
public class VendingMachine extends HttpServlet {
String[] snacks = {“Chips”, “Popcorn”, “Peanuts, . . . } ;
public void doGet(HttpServletRequest req,
HttpServletResponse resp) throws . . . {
resp.setContentType(“text/html”) ;
PrintWriter out = resp.getWriter() ;
String [] selections = req.getParameterValues(“selection”) ;
out.println(“<html><head></head><body>”) ;
for(int i = 0 ; i < snacks.length ; i++) {
out.println(“<form action=” + selectURL + “>”) ;
out.println(“<input type=submit name=selection ” +
“value=\“” + snacks [i] + “\”>”) ;
printHidden(out, selections) ; // print hidden fields
. . . generate form element for viewing current selections . . .
out.println(“</body></html>”) ;