<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<h2>签名&验证</h2>
<form method="post" action="signed.do">
<table border="0">
<tr>
<td aligh="right">姓名</td>
<td aligh="left"><input type="text" name="name" size="20"></td>
</tr>
<tr>
<td aligh="right">E-mail</td>
<td aligh="left"><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td aligh="right">年纪</td>
<td aligh="left">
<input type="radio" name="age" value="18">小于18
<input type="radio" name="age" value="18-25">18-25
<input type="radio" name="age" value="26-40">26-40
<input type="radio" name="age" value=">40">大于40
</td>
</tr>
<tr>
<td aligh="right">编程时间</td>
<td aligh="left">
<select name="codetime" size=1>
<option value="never">不编程
<option value="6">小于6个月
<option value="6-12">6-12个月
<option value="12-24">1到2年
<option value=">24">超过2年
</select>
</td>
</tr>
<tr>
<td aligh="right">使用的操作系统</td>
<td aligh="left">
<select name="os" size=6 multiple>
<option value="WinXP">WinXP
<option value="Win2000">Win2000
<option value="Linux">Linux
<option value="FreeBSD">FreeBSD
<option value="MacOS">MacOS
<option value="other">other
</select>
</td>
</tr>
<tr>
<td aligh="right">使用的编程语言</td>
<td aligh="left">
<input type="checkbox" name="language" value="C">C
<input type="checkbox" name="language" value="C++">C++
<input type="checkbox" name="language" value="C#">C#
<input type="checkbox" name="language" value="Python">Python
<input type="checkbox" name="language" value="Java">Java
<input type="checkbox" name="language" value="VB">VB
<input type="checkbox" name="language" value="Delphi">Delphi
</td>
</tr>
<tr>
<td aligh="right">建议</td>
<td aligh="left">
<textarea name="comment" cols="45" rows="4"></textarea>
</td>
</tr>
<tr><td></td>
<td>
<button type="submit" name="button" >tijiao</button>
<button type="submit" name="button" >tijiao2</button>
</td>
</tr>
</table>
</form>
<body>
</body>
</html>
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/signed.do")
public class test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>display survey information</TITLE></HEAD>");
out.println(" <BODY>");
out.println("<h2>用户输入的信息</h2>");
out.println("<h2>" + request.getParameter("button") + "<h2>");
if(("tijiao".equals(request.getParameter("button"))))
{
out.println("用户名:"+request.getParameter("name")+"<br>");
out.println("e-mail:"+request.getParameter("email")+"<br>");
out.println("年纪:"+request.getParameter("age")+"<br>");
out.println("编程时间:"+request.getParameter("codetime")+"<br>");
out.println("你使用的操作系统:");
printValues(out,request.getParameterValues("os"));
out.println("你使用的编程语言:");
printValues(out,request.getParameterValues("language"));
out.println("建议:"+request.getParameter("comment")+"<br>");
}
if(("tijiao2".equals(request.getParameter("button"))))
{
out.println("<h2>tijiao2<h2>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void printValues(PrintWriter out,String[] values){
if(values==null || values.length==0)
return;
out.println("<ul>");
for(int i=0;i<values.length;i++){
out.println("<li>"+values[i]+"</li>");
}
out.println("</ul>");
}
}