servlet 代码 ShowParameters.java ：

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.*;

public class ShowParameters extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=gb2312");

PrintWriter out = response.getWriter();

String title = "项目信息登记完成，您的项目信息如下";

out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +

"Transitional//EN\">\n" +

"<HTML>\n" +

"<HEAD><TITLE>"+title+"</TITLE></HEAD>\n" +

"<BODY>\n" +

"</BODY></HTML>");

out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" +

"<H4 ALIGN=CENTER>" + title + "</H4>\n" +

"<TABLE BORDER=1 ALIGN=CENTER WIDTH=400>\n" +

"<TR BGCOLOR=\"#FFAD00\">\n" +

"<TH>参数名<TH>参数值");

Enumeration<?> paramNames = request.getParameterNames();

while(paramNames.hasMoreElements()) {

String paramName = (String)paramNames.nextElement();

out.println("<TR><TD>" + paramName + "\n<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>\n</BODY></HTML>");

}

//这里把信息传递给 servlet

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

doGet(request, response);

}

}

postform.htm 内容：

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>A Sample FORM using POST</TITLE>

</HEAD>

<BODY BGCOLOR="#FDF5E6">

<H1 ALIGN="CENTER">项目信息登记</H1>

<FORM ACTION="ShowParameters"

METHOD="POST">

项目编号:

<INPUT TYPE="TEXT" NAME="itemNum"><BR>

数量:

<INPUT TYPE="TEXT" NAME="quantity"><BR>

单价:

<INPUT TYPE="TEXT" NAME="price" VALUE="$"><BR>

<CENTER>

<INPUT TYPE="SUBMIT" VALUE="提交">

</CENTER>

</FORM>

</BODY>

</HTML>

三、部署

1、把 postForm.htm 文件复制到我们的 web 应用目录/jsp_test

2、把 ShowParameters.class 类复制到/jsp_test/WEB-INF/classes 目录下

3、在 web.xml 下添加下面内容：

<servlet>

<servlet-name>ShowParameters</servlet-name>

<servlet-class>ShowParameters</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>ShowParameters</servlet-name>

<url-pattern>/ShowParameters</url-pattern>

</servlet-mapping>

4、 重启 Tomcat

5、 有浏览器打开：

http ://localhost:8080/jsp_test/postForm.htm