Javaweb Summary (i)

Source: Internet
Author: User
Tags html form

While learning the Web application Client interface design, we already know that a basic Web application requires a Web server, a Web client browser, an HTTP protocol, and a static HTML file.

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

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

HTML: Tells the user how the browser displays content to the user;

Http:web the protocol used to communicate between the client and the server;

HTTP

HTTP is a Hypertext Transfer Protocol (hypertext Transfer Protocol), which is a set of rules for computers to communicate in a network. In the TCP/IP architecture, HTTP belongs to the application-layer protocol, which is located at the top of the TCP/IP protocol. HTTP is a stateless protocol (there is no 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 the Web server returns a response (Response). Then the link is closed. HTTP follows the request/response (Request/response) model, and all communication interactions are constructed in a set of request and response models.
HTTP-defined transactions consist of the following four steps

Establish a link between the client and the Web server;

The client sends an HTTP request;

The server-side receives HTTP requests from the client, generating an HTTP response postback;

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 a request line, a request header, a message body, and a blank line separating the request header and the body of the message;
Request line: The request line is an ASCII text line consisting of three tokens: the requested HTTP method, the requested URL, and the HTTP version. The middle is separated by a space

In HTTP version 1.1, there are eight possible HTTP request methods defined

Ⅰ GET: Due to the retrieval of resources to the server;

Ⅱ POST: Due to sending data to the server and requesting the specified URL processing;

Ⅲ Head: As with the Get method, the server returns only the status line and header, and does not return the requested document;

Ⅳ PUT: The request server holds the request data as a new content for the specified URL;

Ⅴ Delete: The request server deletes the named resource in the URL;

Ⅵ OPTIONS: Request information about the server support request method;

Ⅶ CONNECT: A method that has been documented but not currently implemented, and is reserved for tunnel processing;
Of these methods, the get and post methods are most commonly used, and several other methods are not very common for web developers.

Method

Request for the method for the method

POST

Enter the URL in the browser address bar;
Click on the HTML link on the current page;
Set the form's method= ' get ' in the HTML form, or do not set it (by default, the GET method commits) and submit the form;

Getget

It is often used to send private information or a lot of information, or upload files. If an application needs to modify data or add data and send requests over HTTP, then the POST method should be used.

Request Header:

The HTTP protocol uses HTTP headers to pass the requested meta information, which is a colon-delimited name/value pair preceded by the name of the HTTP header followed by the HTTP value. A common request header is a user agent profile, an acceptable format, a language, and a content encoding, which is used to tell the server what the client is, what form of feedback the client wants to receive, and so on.

Blank line:

Send carriage returns and regressions, notifying the server that there are no more request headers.

Message body:

In the case of an HTTP request with a query string, if it is a GET method, the query string or form data is attached to the request line, then there is no content in the body of the message, and if it is a post method, the query string or form data is added to the body of the message.

Loopback Response Message

The Web server resolves the request, locates and reads the specified resource. Returns the file and other information that constitutes an HTTP response to the client. The HTTP response includes a status line, a response header, a message body, and a blank line separating the message header and the response header.

Status line:

Each HTTP response begins with a status line. The status line consists of the HTTP protocol version, the response status code, and the response description, separated by a space between the three.

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

Ⅰ 100~199: Information, request received, continue processing;

Ⅱ 200~299: Success, Behavior is successfully accepted, understood and adopted;

Ⅲ 300~399: Redirect, in order to complete the request, the action must be further executed;

Ⅳ 400~499: Client error, request contains syntax error or request cannot be implemented;

Ⅴ 500~599: Server error, the server can not implement an obvious invalid request;

Each response status code has a string response description associated with it.

Response header:

The response header, like the request header, is also a colon-delimited name/value pair, preceded by 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 stamp, server information, and the time the content was last changed. This information helps the client get what is sent, the size of the content, and whether the data is updated than 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 typically associated with an accept in the HTTP request header

Blank line:

The last response header is followed by a blank line that sends a carriage return and regression, indicating that the following no longer has a response header.

Message body:

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

Close Connection

After the HTTP response arrives at the client, the browser resolves the status line in the HTTP response to see if the request was successful in the status code. Then parse each response header, read the response message body, render the body of the message on the browser page.

An HTML document may contain other resources that need to be loaded, the browser will recognize and make additional requests for those resources, and the process can be recycled until all data is restored to the page in the format specified in the response header. After the data is transferred, the server shuts down the connection, which is the stateless protocol.

Javaweb Summary (i)

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.