Java Web Summary (1), Java Web Summary (

Source: Internet
Author: User

Java Web Summary (1), Java Web Summary (

When learning about the Web application client interface design, we already know that a basic Web application requires Web servers, Web Client browsers, HTTP protocols, and static HTML files.

Web server: receives client requests and returns some results to the client;

Browser: allows the user to request a resource on the server and display the request result to the user;

HTML: shows the user's browser how to display content to the user;

HTTP: the protocol used for communication between the Web client and the server;

HTTP

HTTP is a HyperText Transfer Protocol (HyperText Transfer Protocol). It is a set of rules for computers to communicate over the network. In the TCP/IP architecture, HTTP belongs to the application layer protocol and is located at the top layer of the TCP/IP protocol. HTTP is a stateless protocol (you do not need to establish a persistent link between a Web browser [client] and a Web server ). The whole process is when a client sends a Request to the server, and then the WEB server returns a Response ). Then the link is closed. HTTP follows the Request/Response model, and all communication interactions are constructed in a set of Request and Response models.
The reason for the HTTP-defined service is as follows:

Establish a link between the client and the Web server;

The client sends an HTTP request;

The server receives the HTTP request from the client and generates an HTTP response;

Establish a link between the client and the Web server;

Send request information

Once a TCP link is established, the Web browser sends a request command to the Web server. The HTTP protocol encapsulates the request information from the client into an HTTP request, which includes the request line, request header, message body, and blank lines that separate the request header and message body;
Request Line: The request line is an ASCII text line consisting of three tags: the HTTP Method of the request, the request URL, and the HTTP Version. Separated by Spaces

In HTTP Version 1.1, eight possible HTTP request methods are defined.

I GET: because resources are retrieved from the server;

Ii post: because data is sent to the server and the specified URL is required for processing;

Iii head: Same as the GET method, the server only returns the status line and header mark, and does not return the request document;

Iv put: The request server saves the request data as the new content of the specified URL;

V delete: Request the server to DELETE the resource named in the URL;

Vi options: request information about the request methods supported by the server;

Vii connect: a documented but not implemented method, reserved for tunnel processing;
Among these methods, we usually use GET and POST methods. Other methods are not very common for Web developers.

Method

Request for this method

POST

Enter the URL in the address bar of the browser;
Click the HTML link on the current webpage;
In an HTML form, set the method of the form to 'get' or do not set it (the default is to submit the GET method), and submit the form;

GETGET

It is usually used to send private information or a large amount of information, or upload files. If an application needs to modify or add data and send requests over HTTP, the post method should be used.

Request Header:

The HTTP protocol uses the HTTP header to transmit the request metadata. The HTTP header is a name/value pair separated by a colon. Before the colon, It is the name of the HTTP header, followed by the HTTP value. Common request headers are user agent information, acceptable formats, languages, and content encoding. These information is used to tell the Server Client what it is, and the client wants feedback information in what format.

Empty rows:

Send carriage return and return, and notify the server that there are no request headers.

Message Body:

When an HTTP request contains a query string, if it is a GET method, the query string or form data is appended to the request line, there is no content in the message body; if it is a POST method, query string or form data is added to the message body.

Response Message

The Web server parses the request, locates and reads the specified resource. The file and other information form an HTTP Response and return it to the client. The HTTP response includes the status line, Response Header, message body, and an empty line that separates the message header and response header.

Status line:

Each HTTP Response starts with a status line. The status line consists of the HTTP protocol version, response status code, and response description, separated by spaces.

The response status code is a three-digit number, which is divided into the following groups:

I 100 ~ 199: information. The request is received and processed;

Ⅱ 200 ~ 299: Successful, accepted, understood, and accepted;

Ⅲ 300 ~ 399: redirection. Further actions must be performed to complete the request;

IV 400 ~ 499: client error. The request contains a syntax error or the request cannot be implemented;

V 500 ~ 599: server error. The server cannot implement an obviously invalid request;

Each response status code has an associated string response description.

Response Header:

The same as the request header, the response header is also a name/value pair separated by colons. Before the colon is the name of the HTTP header, followed by the value of the HTTP header. A typical response header includes the content description, content length, time postmark, server information, and the last modification time of the content. This information helps the client obtain the content sent, the size of the content, and whether the data is updated in response to the previous response.

In the response header, the most important HTTP header is Content-Type, which specifies the MIME Type. The MIME type tells the browser what type of data to accept, so that the browser knows how to display the data. This value is usually related to Accept in the HTTP request header.

Blank line:

After the last response header is a blank line, the carriage return and fallback are sent, indicating that there are no response headers below.

Message Body:

HTML document to be sent to the client or other content to be displayed. The Web server places the document information sent to the client in the message body.

Close connection

After the HTTP response arrives at the client, the browser first parses the status line in the HTTP Response to check whether the request is successful. Parse each response header, read the Response Message Body, and render the message body on the browser page.

An HTML document may contain other resources that need to be loaded. the browser recognizes these resources and makes additional requests to them, this process can be recycled until all data is restored to the page according to the format specified in the response header. After data transmission is complete, the server closes the connection, that is, the stateless protocol.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.