4.Servlet_Form表单处理

1.建项目"3Servlet_Form",src下建包“com.amaker.servlet”,web-root下建Register.html
<!DOCTYPE html>
<html>
<head>
<title>Register.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=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head> <body>
<form name="f1" action="/3Servlet_Form/servlet/RegisterServlet" method="post">
<table border="0">
<tr>
<td>隐藏域:</td>
<td><input type="hidden" name="useid" ></td>
</tr> <tr>
<td>用户名称:</td>
<td><input type="text" name="usename" ></td>
</tr> <tr>
<td>密码:</td>
<td><input type="password" name="password" id="password"></td>
</tr> <tr>
<td>性别:</td>
<td><input type="radio" name="gender" value="1" >男
<input type="radio" name="gender" value="2" >女</td>
</tr> <tr>
<td>爱好:</td>
<td><input type="checkbox" name="hobby" value="1" >篮球
<input type="checkbox" name="hoddy" value="2" >网球</td>
</tr> <tr>
<td>职位:</td>
<td><select name="position">
<option name="ceo">CEO</option>
<option name="cto">CTO</option>
<option name="cfo">CFO</option>
</select>
</td>
</tr> <tr>
<td>备注信息:</td>
<td><textarea row="10" colu="20" name="meno"></textarea> </td>
</tr> <tr>
<td colspan="2" align="center"><input type="submit" value="注册"></td>
</tr>
</table>
</form>
</body>
</html>

2.在包下new->servlet->RegisterServlet

该doget和dopost的方法体

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String usename=request.getParameter("usename");
String password=request.getParameter("password");
String gender=request.getParameter("gender");
//读取多个参数
String position=request.getParameter("position");
String meno=request.getParameter("meno");
//得到页面参数 // response.setContentType("text/html");
PrintWriter out = response.getWriter();
// out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
// out.println("<HTML>");
// out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
// out.println(" <BODY>");
out.println("Usename:"+usename);
out.print("Passwod:"+password);
out.print("Gender:"+gender);
//for(int i=0;i<2;i++){ //out.print("hobby:"+hobby[i]); //} out.print("Postion:"+position);
out.print("meno:"+meno); // out.println(" </BODY>");
// out.println("</HTML>");
// out.flush();
// out.close();
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request, response);
//调用函数,只写一个函数看看效果
}
4.Servlet_Form表单处理
上一篇:Search in Rotated Sorted Array I II


下一篇:初步认识express,并创建web服务器,挂载静态资源