package forms; import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; /** * A servlet to demonstrate the use of parameters in HTML forms. * * @version 1.0 2001/08/15 * @author Mike Gehard */ public class Parameters extends HttpServlet{ /** * Handle POST request. * 1) Reads all request parameters and prints them out to the screen * * @param request the HTTPServletRequest associated with this servlet * @param response the HTTPServletResponse associated with this servlet * @throws ServletException * @throws IOException * */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(" Parameters"); out.println(""); out.println(""); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String values[] = request.getParameterValues(name); if (values != null) { for (int i = 0; i < values.length; i++) { out.println(""); } } } out.println("
" + name + "" + values[i] + "
"); out.println(""); out.println(""); } /** * Handle GET request. * Delagates to doPost(). * * @param request the HTTPServletRequest associated with this servlet * @param response the HTTPServletResponse associated with this servlet * @throws ServletException * @throws IOException * */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ // forward to doPost() doPost(request, response); } }