import java.io.* ; import javax.servlet.* ; import javax.servlet.http.* ; import java.util.* ; public class ShowAllFormData extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html") ; PrintWriter out = response.getWriter() ; String title = "显示所有的Form变量的值" ; out.println("<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD>" + "<BODY BGCOLOR=#FDF5E6>" + "<H1 ALIGN=CENTER>" + title + "</H1>" + "<TABLE BORDER=1 ALIGN=CENTER>" + "<TR BGCOLOR=#FFAD00>" + "<TH>变量名称<TH>变量值") ; Enumeration paramNames = request.getParameterNames() ; while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement() ; out.println("<TR><TD>" + paramName + " < TD > "); String[] paramValues = request.getParameterValues(paramName) ; if (paramValues.length == 1) { String paramValue = paramValues[0] ; if (paramValue.length() == 0) out.print("<I>No Value</I>") ; else out.print(paramValue) ; } else { out.println("<UL>") ; for (int i = 0 ; i < paramValues.length ; i++) { out.println("<LI>" + paramValues[i]) ; } out.println("</UL>") ; } } out.println("</TABLE> < / BODY > < / HTML > ") ; } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response) ; } } |