//: c16:EchoForm.java // From Thinking in Java, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 1999 // Copyright notice in Copyright.txt // Dumps the name-value pairs of any HTML form import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class EchoForm extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.print("

Your form contained:

"); Enumeration flds = req.getParameterNames(); while(flds.hasMoreElements()) { String field = (String)flds.nextElement(); String value = req.getParameter(field); out.print(field + " = " + value + "
"); } out.close(); } } ///:~