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

2016-01-29 12:05 5 1 收藏

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

【 tulaoshi.com - Java 】

  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"n" +
"<H1 ALIGN=CENTER" + title + "</H1n" +
"<TABLE BORDER=1 ALIGN=CENTERn" +
"<TR BGCOLOR="#FFAD00"n" +
"<THParameter Name<THParameter Value(s)");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.print("<TR<TD" + paramName + "n<TD");
String[] paramValues =
request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.println("<INo 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("</TABLEn</BODY</HTML");
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

来源:http://www.tulaoshi.com/n/20160129/1484580.html

延伸阅读
标签: Web开发
修改地址后的参数: script function getNewUrl(oldurl,paramname,pvalue){     var reg = new RegExp("(\\?|&)"+ paramname +"=([^&]*)(&|$)","gi");     var t=oldurl.match(reg)[0];     var retxt=t.substring(0,t.indexOf("=")+1)+pvalue;     if(t.charAt(t.length-1)=='...
标签: Java JAVA基础
如果任务已经启动,isStarted()方法将返回true: public synchronized boolean isStarted() {     return started; }   如果任务已经完成,isCompleted()方法将返回true: public synchronized boolean isCompleted() {     return counter == 100; }   如果任务正在运行,isRu...
标签: Java JAVA基础
  比如来自Blazix服务器的标志库在你的系统环境中不能使用,那么不使用标志库来实现相似的功能呢?本教程就是为这个问题而提出的。这个问题是可以解决的,只是代码要长一点。主要地,你必须亲自编辑HTML标志,然后将它设置缺省值。从下面的例子的例子中我们可以学到怎样修改GetName.jsp以提供类似于blx:getProperty的特性,但是我们只...
标签: Web开发
代码如下: ?xml version="1.0" encoding="UTF-8" ? !DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" %@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"% %@ page import="java.net.*"% % String location = ""; String location...
标签: Java JAVA基础
  vishal_donth gave this response on 10/18/2000:   //these are the pakages to be imported from   // Java Mail   //The Java Mail PAckage either be dowloaded   //seperately   //or else is Available in the J2sdkee1.2   // (Java Enterprise Edition) &nbs...

经验教程

722

收藏

62
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部