当前位置:首页 > 网络编程 > WEB编程 > JSP > jsp源码实例2(获取表单参数)

jsp源码实例2(获取表单参数)

点击次数:25 次 发布日期:2008-11-26 15:52:14 作者:源代码网
源代码网推荐 package coreservlets;
源代码网推荐
源代码网推荐 import java.io.*;
源代码网推荐 import javax.servlet.*;
源代码网推荐 import javax.servlet.http.*;
源代码网推荐 import java.util.*;
源代码网推荐
源代码网推荐 /** Shows all the parameters sent to the servlet via either
源代码网推荐 * GET or POST. Specially marks parameters that have
源代码网推荐 * no values or multiple values.
源代码网推荐 * <P>
源代码网推荐 * Taken from Core Servlets and JavaServer Pages
源代码网推荐 * from Prentice Hall and Sun Microsystems Press,
源代码网推荐 * http://www.coreservlets.com/.
源代码网推荐 * &copy; 2000 Marty Hall; may be freely used or adapted.
源代码网推荐 */
源代码网推荐
源代码网推荐 public class ShowParameters extends HttpServlet {
源代码网推荐 public void doGet(HttpServletRequest request,
源代码网推荐 HttpServletResponse response)
源代码网推荐 throws ServletException, IOException {
源代码网推荐 response.setContentType("text/html");
源代码网推荐 PrintWriter out = response.getWriter();
源代码网推荐 String title = "Reading All Request Parameters";
源代码网推荐 out.println(ServletUtilities.headWithTitle(title) +
源代码网推荐 "<BODY BGCOLOR="#FDF5E6"> " +
源代码网推荐 "<H1 ALIGN=CENTER>" + title + "</H1> " +
源代码网推荐 "<TABLE BORDER=1 ALIGN=CENTER> " +
源代码网推荐 "<TR BGCOLOR="#FFAD00"> " +
源代码网推荐 "<TH>Parameter Name<TH>Parameter Value(s)");
源代码网推荐 Enumeration paramNames = request.getParameterNames();
源代码网推荐 while(paramNames.hasMoreElements()) {
源代码网推荐 String paramName = (String)paramNames.nextElement();
源代码网推荐 out.print("<TR><TD>" + paramName + " <TD>");
源代码网推荐 String[] paramValues =
源代码网推荐 request.getParameterValues(paramName);
源代码网推荐 if (paramValues.length == 1) {
源代码网推荐 String paramValue = paramValues[0];
源代码网推荐 if (paramValue.length() == 0)
源代码网推荐 out.println("<I>No Value</I>");
源代码网推荐 else
源代码网推荐 out.println(paramValue);
源代码网推荐 } else {
源代码网推荐 out.println("<UL>");
源代码网推荐 for(int i=0; i<paramValues.length; i++) {
源代码网推荐 out.println("<LI>" + paramValues);
源代码网推荐 }
源代码网推荐 out.println("</UL>");
源代码网推荐 }
源代码网推荐 }
源代码网推荐 out.println("</TABLE> </BODY></HTML>");
源代码网推荐 }
源代码网推荐
源代码网推荐 public void doPost(HttpServletRequest request,
源代码网推荐 HttpServletResponse response)
源代码网推荐 throws ServletException, IOException {
源代码网推荐 doGet(request, response);
源代码网推荐 }
源代码网推荐 }
源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华