get和post的区别:
http://localhost:8080/smart_toilet/show.jsp?uname=23&upwd=3425&uage=123 get方式(地址栏最多可以容纳4-5KB,如何请求大文件会出现容纳出错)
localhost:8080/smart_toilet/show.jsp post方式(文件上传操作必须时post)
注册界面:register.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>智慧厕所用户注册</title> 8 </head> 9 <body> 10 <form action="show.jsp" method=“post”> 11 用户名:<input type="text" name="uname"/><br/> 12 密码:<input type="password" name="upwd"/><br/> 13 年龄:<input type="text" name="uage"/><br/> 14 年龄:<input type="checkbox" name="up" value = "男"/>男 15 <input type="checkbox" name="up" value = "女"/>女 16 <br/> 17 <input type="submit" value="注册"> 18 </form> 19 20 </body> 21 </html>
显示界面:show.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>用户注册显示界面</title> 8 </head> 9 <body> 10 <% 11 //设置编码 12 request.setCharacterEncoding("utf-8"); 13 String name = request.getParameter("uname"); 14 int age =Integer.parseInt(request.getParameter("uage")); 15 String pwd = request.getParameter("upwd"); 16 String[] up = request.getParameterValues("up"); 17 %> 18 注册成功,信息如下:<br/> 19 姓名:<%=name%><br/> 20 年龄:<%=age%><br/> 21 密码:<%=pwd%><br/> 22 性别: 23 <%
if (up !=null) 24 for(String manorfileman:up) 25 { 26 out.print(manorfileman+" ");//" "空格的意思 27 }%> 28 </body> 29 </html>