Java-wed Early Acquaintance

Source: Internet
Author: User
Tags html form

Parsing the HTTP protocol:
HTTP is a Hypertext Transfer Protocol (HYPERTEXTTRANSFERPROTOCOL), 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, meaning that 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), and then it shuts down.

The HTTP definition of the things handled consists of the following four steps:
1. Client and Web server establish connection
2. Client sends HTTP request
3. HTTP request from server-side client, generate HTTP response postback
4. Close the connection on the server side. I will parse the postback response. Restore the page.

The format of HTTP is as follows:
Http://bost (Host) [":" Post (port)][abs_path (absolute path)]


Features of the HTTP protocol:
1. Support client/server mode
2. Simple and fast
3. Flexible (allows any type to be transmitted)
4. No connection (just connect when sending the request, close the connection when the response is complete)
5. Stateless (can transfer any method and path, and will not process transactions and save)


-------------------------------------------Split a line-----------------------------------------------

Send Request message:
 1. Request Line: The
   request line is an ASCII line of text consisting of three tokens: Http method, requested URL, HTTP version, separated by a space in the middle. Columns such as:
   get/lookbook/index.html http/1.0
   in HTTP version 1.1, there are eight possible HTTP request methods defined:
   1.get: Used to retrieve resources from the server
   2.post: Used to send data to the server and requires the specified URL handling
   3. HEAD: As with the Get method, the server returns only the status row and header, and does not return the request document
   4.put: The request server holds the request data as the new content of the specified URL
   5. Delete: The request server deletes the named resource in the URL
   6.options: Requests information about the request method that the server supports
   7. TRACE: Request Web I fully feedback HTTP request and its header
   8.connect: documented but currently implemented as a method, reserved for tunnel processing

The HTTP request is a GET method in the following way:
1. Enter the URL in the browser address bar
2. Click on the HTML connection on the current page
3. Set the form's method= ' get ' in the HTML form and submit the form
4. The form's method attribute submission form is not set in the HTML form (default is Get method if the method property is not set)
2. Request Header:
The HTTP protocol uses HTTP headers to pass the requested meta information, HTTP is a colon-delimited name/value pair, the colon is preceded by the name of HTTP, followed by the value of HTTP.
3. Blank line:
Send enter to conform to the regression, notify the server no longer have the request header
4. Message body:
In an HTTP request with a query string, if it is an CET method, the query string or form data is attached to the request line, and the message body has no content. In the case of the Post method, the query string or form data is added to the body of the message.

-------------------------------------------Split a line-----------------------------------------------

Loopback Response Information:
HTTP responses include: status lines, response headers, message bodies, and a blank line of split message headers and response headers
1. Status line:
The response status code is a three-bit number that is divided into the following categories:
1.1XX: Information, request received, continue processing
2.2XX: Success, successful acceptance, understanding and adoption
3.3XX: Redirect (cannot solve the problem, new solution), in order to complete the request, the action must be further executed
4.4xx: Client error, request contains syntax error or request cannot be implemented
5.5XX: Server error, server cannot implement an apparently invalid request
Common Response Codes:
200: Client Request succeeded
400: Client request syntax error, cannot be understood by the server
401: Request Unauthorized
403: Server receives request, denial of service
404: Request resource does not exist
500: An unpredictable error occurred on the server
503: Server cannot process, may recover later
2. Response header:
In the response header, the most important HTTP header is Content-type, which specifies the MIME type.
3. Blank line:
The last response header is followed by a blank line, which sends a return to the regression, indicating that the following no longer has a response header
4. Message body:
The HTML document or other content to be displayed for the client to be sent. Wed server to put the document information sent to the client in the message body


-------------------------------------------Split a line-----------------------------------------------


Web server flaw (original Web server):
A Web server is actually used to provide HTTP services to clients, and it can only provide static Web page content to clients. If we need a dynamic page (a dynamically created page that does not exist before the request is made), and you want to save the data that was submitted through the form or query string on the pouch server (that is, write a file or database), the original web cannot be resolved.


Server-side Web page programming:
Includes the earliest CGI technology, Microsoft's ASP and ASP, and the Java-based servlet/jsp technology.

The earliest solution CGI:
CGI, which is the Gateway Interface (COMMOM Gateway Interface), is the first technology to create dynamic server-side content. CGI success is the standard way to create dynamic Web pages. The great advantage of CGI is that he can write with Shell, Perl, C, PHP, Python, and so on. But not perfect. When the CGI is running, the memory of the server is severely consumed by the way a CGI process is opened each time it is requested.

Solutions for Java:
In the Java World, Servle and web containers are designed to solve CGI problems and create a robust server environment for Web developers.
Servle:
Servle is a platform-agnostic Java class that can be compiled into platform-neutral bytecode, which is dynamically loaded and run by Java-based Web servers.
Every Web application has to have the Web-inf directory, the. xml file, and the classes directory. That
Appname\
Appname\web-inf
Appname\web-inf\web.xml
Appname\web-inf\classes

Java-wed Early Acquaintance

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.