Java doGet() 和 doPost() 在流程方面有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27040389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:43:39  来源:igfitidea点击:

what is the difference between doGet() and doPost() in term of the flow?

javaservlets

提问by shamil khairi

the difference in term of the flow, i know that doGet() is the pre-processing and dopost is post-processing, but what is that?

流程方面的差异,我知道 doGet() 是预处理,dopost 是后处理,但那是什么?

采纳答案by Stephen C

the difference in term of the flow, i know that doGet() is the pre-processing and dopost is post-processing, but what is that?

流程方面的差异,我知道 doGet() 是预处理,dopost 是后处理,但那是什么?

Actually, the methods are nothing to do with "pre-processing" and "post-processing".

实际上,这些方法与“预处理”和“后处理”无关。

To understand what the methods are for, you need some basic understand of the HTTP protocol.

要了解这些方法的用途,您需要对 HTTP 协议有一些基本的了解。

HTTP is a request-reply protocol: the client (e.g. a web browser) sends a request, and the server (e.g. a web server) responds with a reply. Each request consists of a "request-line", a series of "header" lines and optionally a "body". A typical request-line looks like this:

HTTP 是一种请求-回复协议:客户端(例如 Web 浏览器)发送请求,服务器(例如 Web 服务器)以回复进行响应。每个请求由一个“请求行”、一系列“标题”行和可选的“正文”组成。典型的请求行如下所示:

  GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

The three parts of this line are:

该行的三个部分是:

In fact, the HTTP specification defines 8 standard HTTP request methods (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE & CONNECT) each of which has a different meaning. (Other methods are defined by other specifications.)

实际上,HTTP 规范定义了 8 种标准的 HTTP 请求方法(GET、PUT、POST、DELETE、HEAD、OPTIONS、TRACE & CONNECT),每种方法都有不同的含义。(其他方法由其他规范定义。)

The doGetand doPostmethods in the ServletAPI are methods for processing HTTP GET and POST requests respectively. In fact there are other "doXxxx" methods matching the other standard HTTP methods ... apart from CONNECT. (The semantics of CONNECT are not applicable to a servlet ...)

API 中的doGetdoPost方法Servlet分别是处理 HTTP GET 和 POST 请求的方法。事实上,除了 CONNECT 之外,还有其他“doXxxx”方法与其他标准 HTTP 方法匹配。(CONNECT 的语义不适用于 servlet ...)

For more information, refer to the HTTP 1.1 Specification, and the HttpServletjavadoc.

有关更多信息,请参阅HTTP 1.1 规范HttpServletjavadoc

回答by Benjamin

This link Detail

这个链接 详情

doGet()and doPost()are HTTP requests handled by servlet classes.

In doGet(), the parameters are appended to the URL and sent along with header information. This does not happen in case of doPost(). In doPost(), the parameters are sent separately. Since most of the web servers support only a limited amount of information to be attached to the headers, the size of this header should not exceed 1024 bytes. doPost() does not have this constraint. Usually programmers find it difficult to choose between doGet() and doPost().

doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request. doPost() shall be used when comparatively large amount of sensitive data has to be sent. Examples are sending data after filling up a form or sending login id and password.

doGet()doPost()是由 servlet 类处理的 HTTP 请求。

在 doGet() 中,参数被附加到 URL 并与标头信息一起发送。在 doPost() 的情况下不会发生这种情况。在 doPost() 中,参数是分开发送的。由于大多数 Web 服务器仅支持将有限数量的信息附加到标头,因此该标头的大小不应超过 1024 字节。doPost() 没有这个约束。通常程序员发现很难在 doGet() 和 doPost() 之间做出选择。

当需要将少量数据和不敏感数据(如查询)作为请求发送时,应使用 doGet()。当需要发送相对大量的敏感数据时,应使用 doPost()。示例是在填写表单或发送登录 ID 和密码后发送数据。