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>