The development of the Internet is very fast , But everything is the same . Study web Development , We need to be right about We have a certain understanding of the interaction mechanism of the Internet . In order to better understand and master Servlet, In formal study Servlet You need to be right about web The interaction mechanism between client and server in the development and the specifications involved (HTTP) To study .
Picture introduction ：
The client requests the server according to the address information entered by the user , The server is receiving users After the request is processed , Then the processing results are responded to the client , The client presents the response results to the user .
Professional term :
request ： The client sends data to the server according to the user address information
Respond to ： The process by which the server sends the processing result of a request to the browser
There are many versions of the client, that is, the browser , There are many versions of the server Of , How to realize the data interaction between different versions of browsers and different versions of servers ？
Standardize the format of data interaction between browser and server .
Realization ：HTTP agreement
Hypertext transfer protocol （Hyper Text Transfer Protocol）
It standardizes the data interaction between browser and server
Simple and fast ： When a client requests a service from the server , Just send the request method and path . The common request methods are GET、HEAD、POST. Each method specifies a different type of client server contact . because HTTP Simple protocol , bring HTTP The program size of the server is small , So communication is fast
flexible ：HTTP Allow transfer of any type of data object . The type being transmitted is by Content-Type To mark .
There is no connection ： Connectionless means that you are limited to one request per connection . The server completes the client's request , And received the customer's response , disconnect . This way you can save transmission time .
No state ：HTTP A protocol is a stateless protocol . Stateless is a protocol that has no memory for transactions . The lack of state means that the previous information is required for subsequent processing , It must be retransmitted , This can lead to an increase in the amount of data transferred per connection . On the other hand , The server responds quickly when it does not need the previous information .
Support B/S And C/S Pattern .
HTTP1.1 Support sustainable connectivity after the release
HTTP There are four steps in the interaction process ( A complete request )： Step one : Establish connection between client and server Step two ： Client sends request data to server (HTTP agreement ) Step three ： After the server receives the request , To deal with , And then Processing results respond to the client (HTTP agreement ) Step four ： Close the connection between the client and the server (HTTP1.1 It won't shut down immediately after )
The structure of the request format ： Request header ： Request mode 、 Requested address and HTTP Protocol version Request line ： The message header , It is generally used to indicate some additional information to be used by the client Blank line ： Between the request line and the request data , It's necessary to have an empty line . Request data ： Not necessary .
Be careful ： The content of a web page is extremely rich , Browsers follow HTTP The format of the request sends valid data to the server .
according to HTTP standard ,HTTP Multiple request methods can be used for requests .
HTTP1.0 Three request methods are defined ： GET, POST and HEAD Method .
HTTP1.1 Five new request methods ：OPTIONS,PUT,DELETE,TRACE and CONNECT Method .
get Request mode ： The request data will be ？ In the request header , unsafe , No, please be realistic The body part . HTTP Although the protocol does not specify the size of the request data , But the browser is right URL Length There is a limit to the degree , therefore get Requests can't carry a lot of data .
post Request mode ： Request data is sent in the requesting entity , stay URL No specific request data can be found in , Security . It is suitable for sending large amount of data .
The structure of the response format ： Response line ( Status line )：HTTP edition 、 Status code 、 Status message Response head ： The message header , Additional information used by the client Blank line ： Between the response header and the response entity , necessary . In response to the entity ： Text , Information returned by the server to the browser
HTTP Common response status code meaning ： HTTP The status code consists of three decimal digits , The first decimal number defines the status code The type of , The last two numbers have no role in classification .HTTP Status codes are divided into 5 Types ：
200 OK // Client request successful
400 Bad Request // Client request has syntax error , Can't be handled by the server Explain
401 Unauthorized // Request not authorized , The status code must be equal to WWW-Authenticate Header fields are used together
403 Forbidden // The server receives the request , But refused to provide service
404 Not Found // The requested resource does not exist ,eg： I typed the wrong one URL
500 Internal Server Error // An unexpected error occurred on the server
503 Server Unavailable // The server is currently unable to process the client's request , It may return to normal after some time