浏览器在提交form表单时有两种提交方式

浏览器在提交form表单时有两种提交方式
一种是get方式,这也是默认的,到服务器端时就会调用处理get请求的doGet方法
而另一种是post方式,这需要在form表单中指定,即 method="post",服务器端会自动调用doPost方法来处理该请求。
而get请求和post请求的区别就是:
get请求在地址栏中以?分隔,后加传递的参数,这样传递的参数是有字符限制的。
post请求不显示参数。
在地址栏输地址按回车, 默认是get请求;

   显示客户端的时间, 将javascript发到客户端即可;

   <script language="javascript">

          document.write(new Date());

   </script>

   想发post请求, 必须写form表单, method="post";

   <form   action="/myapp/basic/complex/time"   method="post">

      <input type="submit"   value="see time">

   </form>


以下是转的完整的:
doGet 和doPost的区别,在什么时候调用,为什么有时doPost中套用doGet
1. 提交的form method=Post就执行doPost,否则执行doGet ,套用是不管method是post还是get都执行dopost方法
2.get: 你可以通过URL传参数http://www.csdn.net/index.asp?user=HelloWorld , Post不行
3. 你的表单提交都有方法的,如果提交为get就调用get方法,用post就调用post方法.
get 显示你传过去的参数,post则不显示.
5. 通常的写法:先用doGet(),然后在doGet()中调用doPost(),这样就万无一失了
6. 简单的说,get是通过http header来传输数据有数量限制,而post则是通过http body来传输数据,没有数量限制
7. 还有一点:get和post提交的数据量是不一样的.
get 好像最多只能在url后跟64K(?具体多少忘记了),
post 好像没这个限制,至少我post过5M以上的文本
还有url刷新时get好像可以不用重复提交原来提交的数据,
而post则会说内容已提交,想刷新请再提交. Parameters:

req - the HttpServletRequest object that contains the request the client made of the servlet
resp - the HttpServletResponse object that contains the response the servlet returns to the client

protected void doPost(HttpServletRequest req,HttpServletResponse resp)
               throws ServletException,java.io.IOException
Called by the server (via the service method) to allow a servlet to handle a POST request.
The HTTP POST method allows the client to send data of unlimited length to the Web server 
a single time and is useful when posting information such as credit card numbers.
protected void doGet(HttpServletRequest req, HttpServletResponse resp)             
throws ServletException,java.io.IOException
Called by the server (via the service method) to allow a servlet to handle a GET request.
Overriding this method to support a GET request also automatically supports an HTTP HEAD request.
A HEAD request is a GET request that returns no body in the response, only the request header fields.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值