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

来源:互联网 发布:潍坊seo林晟科技 编辑:程序博客网 时间:2024/04/30 07:37
浏览器在提交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>


以下是转的完整的:
doGetdoPost的区别,在什么时候调用,为什么有时doPost中套用doGet

1.提交的formmethod=Post就执行doPost,否则执行doGet ,套用是不管methodpost还是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是通过httpheader来传输数据有数量限制,而post则是通过httpbody来传输数据,没有数量限制
7.还有一点:getpost提交的数据量是不一样的.
get好像最多只能在url后跟64K(?具体多少忘记了),
post好像没这个限制,至少我post5M以上的文本
还有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.