表单(form)的提交实现参数页面间的传递

 表单(form)的提交实现参数页面间的传递

  在介绍表单传递参数的内容之前,先来了解一些预备知识。表单的提交方式和请求报文中对汉字的处理。

  表单的提交方式:

  通常使用的表单的提交方式主要是:post和get两种。两者的区别在于:post方式是把数据内容放在请求的数据正文部分,没有长度的限制;get方式则是把数据内容直接跟在请求的头部的URL后面,有长度的限制。下面是同一个页面两种方式的请求报许文。

  Requesttest.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>Insert title here</title>    
  8. </head>    
  9. <body>    
  10. <%-- post方式提交表单 --%>    
  11. <form action="http://localhost:8888/EncodingTest/requestresult.jsp" method="post">    
  12.     UserName:<input type="text" name="username"/>    
  13.     Password:<input type="password" name="password"/>    
  14.     <input type="submit" value="Submit">    
  15. </form>    
  16. </body>    
  17. </html>   
 
 
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%-- post方式提交表单 --%> <form action="http://localhost:8888/EncodingTestb/requestresult.jsp" method="post"> UserName:<input type="text" name="username"/> Password:<input type="password" name="password"/> <input type="submit" value="Submit"> </form> </body> </html>  

  在上面的请求页面的username输入框里输入的是“世界杯”三个汉字,password输入框中输入"123"后按下Submit按钮提交请求。截获到的请求报文如下:

  Post方式的请求报文代码

  1. POST /EncodingTest/requestresult.jsp HTTP/1.1   
  2. Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*    
  3. Referer: http://localhost:8080/TomcatJndiTest/requesttest.jsp    
  4. Accept-Language: zh-cn    
  5. User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; aff-kingsoft-ciba; .NET CLR 2.0.50727)    
  6. Content-Type: application/x-www-form-urlencoded    
  7. Accept-Encoding: gzip, deflate    
  8. Host: localhost:8888   
  9. Content-Length: 49   
  10. Connection: Keep-Alive    
  11. Cache-Control: no-cache    
  12.    
  13. username=%E4%B8%96%E7%95%8C%E6%9D%AF&password=123   
  14. POST /EncodingTest/requestresult.jsp HTTP/1.1 Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* Referer: http://localhost:8080/TomcatJndiTest/requesttest.jsp Accept-Language: zh-cn User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; aff-kingsoft-ciba; .NET CLR 2.0.50727) Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate Host: localhost:8888 Content-Length: 49 Connection: Keep-Alive Cache-Control: no-cache username=%E4%B8%96%E7%95%8C%E6%9D%AF&password=123  

  以上报文内容,可以看出post方式的请求报文是有专门的数据部的。,

  下面的同一请求页面的get提交方式的请求报文:

  Get方式的请求报文代码

  1. GET /EncodingTest/requestresult.jsp?username=%E4%B8%96%E7%95%8C%E6%9D%AF&password=123 HTTP/1.1   
  2. Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*    
  3. Referer: http://localhost:8080/TomcatJndiTest/requesttest.jsp    
  4. Accept-Language: zh-cn    
  5. User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; aff-kingsoft-ciba; .NET CLR 2.0.50727)    
  6. Accept-Encoding: gzip, deflate    
  7. Host: localhost:8888   
  8. Connection: Keep-Alive   
  9. GET /EncodingTest/requestresult.jsp?username=%E4%B8%96%E7%95%8C%E6%9D%AF&password=123 HTTP/1.1 Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* Referer: http://localhost:8080/TomcatJndiTest/requesttest.jsp Accept-Language: zh-cn User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; aff-kingsoft-ciba; .NET CLR 2.0.50727) Accept-Encoding: gzip, deflate Host: localhost:8888 Connection: Keep-Alive  

  以上报文内容,可以看出get方式的请求报文没有专门的数据部,数据是直接跟在url的后面。网上商城系统


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值