package forms; import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.ecs.*; import org.apache.ecs.html.*; /** * A servlet to demonstrate the use of parameters in HTML forms. * It also uses ECS to format the results. * * @version 1.0 2001/08/15 * @author Mike Gehard */ public class Parameters2 extends HttpServlet{ /** * Handle POST request. * 1) Reads all request parameters and prints them out to the screen * 2) Use element construction set (ECS) to format results * * @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(); Table table = new Table(0); // border = 0 // create the HTML tree Html html = new Html(); Head head = new Head(); Title title = new Title("Parameters with ECS"); Body body = new Body(); head.addElement(title); body.addElement(table); html.addElement(head); html.addElement(body); /* This gets replaced with the above code out.println(""); out.println(" Parameters"); out.println(""); out.println(""); */ Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { //System.out.println("e.hasMoreElements() = true"); String name = (String) e.nextElement(); //System.out.println("Name= " + name); String values[] = request.getParameterValues(name); //System.out.println("values[] length = " + values.length); if (values != null) { for (int i = 0; i < values.length; i++) { TR tr = new TR(); TD col1 = new TD(); TD col2 = new TD(); I it = new I(); Font font = new Font(); table.addElement(tr); tr.addElement(col1); tr.addElement(col2); col1.addElement(it); it.addElement(font); font.setColor(HtmlColor.BLUE); font.addElement(name); col2.addElement(values[i]); /*Replaced by the above code out.println(""); */ } } } out.println(html); } /** * 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); } }
" + name + "" + values[i] + "