寫一個注冊頁面,將之前的知識串聯起來
連接/文件? 參數名1=參數值1 & 參數名2=參數值2 & 參數名3 = 參數值3
get的提交方式: method="get" 和 地址欄、超鏈接<a href="xx"> 請求方式默認都屬於get提交方式
register.jsp
show.jsp
頁面效果

上傳表單后:

2.get 和post方式的區別
-
get方式在地址欄顯示 請求信息;但是地址欄能夠容納的信息有限,4-5kb;(如果請求數據存在大文件,圖片等,會出現地址欄無法容納數據而報錯),post不會顯示
-
文件上傳的操作,必須是post。 一般推薦使用Post.因為更加安全
3.統一編碼
### 統一請求編碼(get)
方法一:統一每一個變量的編碼(不推薦)
new String(舊編碼,新編碼);
name = new String(name.getBytes("iso-8859-1"),UTF-8);
方法二: 修改servers里的server.xml,一次性的更改tomcat默認get提交方式的編碼(utf-8);建議使用tomcat時,首先在server.xml中統一get方式的編碼,URIEncoding="UTF-8"
大約在63行的位置: <Connector connectionTimeout="20000" port="8888" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
post的改法
request.setCharacterEncoding("utf-8");
<% //設置編碼 request.setCharacterEncoding("UTF-8"); String name = request.getParameter("uname"); String pwd = request.getParameter("upwd"); int age = Integer.parseInt(request.getParameter("uage"));
String[ ] hobbies = request.getParameterValues("uhobbies");
%>
注冊成功,信息如下:<br/>
姓名:<%= name%> <br/>
年齡:<%= age%> <br/>
密碼:<%= pwd%> <br/>
愛好:
<%


