Servlet学习
HTTP Requests
The request sent by the computer to a web server, contains all sorts of potentially interesting information; it is known as HTTP requests.
The HTTP client sends the request to the server in the form of request message which includes following information:
- The Request-line
- The analysis of source IP address, proxy and port
- The analysis of destination IP address, protocol, port and host
- The Requested URI (Uniform Resource Identifier)
- The Request method and Content
- The User-Agent header
- The Connection control header
- The Cache control header
The HTTP request method indicates the method to be performed on the resource identified by the Requested URI (Uniform Resource Identifier). This method is case-sensitive and should be used in uppercase.
The HTTP request methods are:
HTTP Request | Description |
---|---|
GET | Asks to get the resource at the requested URL. |
POST | Asks the server to accept the body info attached. It is like GET request with extra info sent with the request. |
HEAD | Asks for only the header part of whatever a GET would return. Just like GET but with no body. |
TRACE | Asks for the loopback of the request message, for testing or troubleshooting. |
PUT | Says to put the enclosed info (the body) at the requested URL. |
DELETE | Says to delete the resource at the requested URL. |
OPTIONS | Asks for a list of the HTTP methods to which the thing at the request URL can respond |
GET要求在被请求的URL中获取资源。
POST要求服务器接受附加的身体信息。这就像GET请求中带有请求的额外信息一样。
HEAD只要求返回的标题部分。就像得到,但没有身体。
TRACE询问请求消息的回环,用于测试或故障排除。
PUT说将所包含的信息(主体)放在所请求的URL中。
DELETE说要在请求的URL中删除资源。
选项要求提供一个HTTP方法的列表,其中请求URL中的东西可以响应
Get vs. Post
There are many differences between the Get and Post request. Let's see these differences:
GET | POST |
---|---|
1) In case of Get request, only limited amount of data can be sent because data is sent in header. | In case of post request, large amount of data can be sent because data is sent in body. |
2) Get request is not secured because data is exposed in URL bar. | Post request is secured because data is not exposed in URL bar. |
3) Get request can be bookmarked. | Post request cannot be bookmarked. |
4) Get request is idempotent . It means second request will be ignored until response of first request is delivered | Post request is non-idempotent. |
5) Get request is more efficient and used more than Post. | Post request is less efficient and used less than get. |
得到后
1)在得到请求的情况下,由于数据是在头中发送的,所以只能发送有限的数据。在post请求的情况下,可以发送大量的数据,因为数据是在正文中发送的。
2)Get请求没有被保护,因为数据是在URL栏中公开的。Post请求是安全的,因为数据不会在URL栏中公开。
3)Get请求可以被标记。Post请求不能被标记。
4)Get请求是幂等的。这意味着第二个请求将被忽略,直到第一个请求的响应被发送后请求是非幂的。
5)Get请求比Post更有效,使用更多。Post请求的效率较低,使用的效率也较低。
GET and POST
Two common methods for the request-response between a server and client are:
- GET- It requests the data from a specified resource
- POST- It submits the processed data to a specified resource
GET-它请求来自指定资源的数据
POST——它将处理过的数据提交给指定的资源
Anatomy of Get Request
The query string (name/value pairs) is sent inside the URL of a GET request:
- GET /RegisterDao.jsp?name1=value1&name2=value2
As we know that data is sent in request header in case of get request. It is the default request type. Let's see what information is sent to the server.
Some other features of GET requests are:
- It remains in the browser history
- It can be bookmarked
- It can be cached
- It have length restrictions
- It should never be used when dealing with sensitive data
- It should only be used for retrieving the data
它仍然存在于浏览器历史中
它可以是书签
它可以被缓存
它有长度限制
在处理敏感数据时不应该使用它
它应该只用于检索数据
Anatomy of Post Request
The query string (name/value pairs) is sent in HTTP message body for a POST request:
- POST/RegisterDao.jsp HTTP/1.1
- Host: www. javatpoint.com
- name1=value1&name2=value2
As we know, in case of post request original data is sent in message body. Let's see how information is passed to the server in case of post request.
Some other features of POST requests are:
- This requests cannot be bookmarked
- This requests have no restrictions on length of data
- This requests are never cached
- This requests do not retain in the browser history
这些请求不能被标记为书签
这些请求对数据的长度没有限制
这些请求永远不会被缓存
这些请求不会在浏览器历史中保留