Java Web presentation layer technology: How java web works

Source: Internet
Author: User

1. How java web works:


Http is stateless.
Send request message:
Once a TCP connection 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, it includes the request line, request header, message body, and an empty line that separates the request header and message body.
Request Line:
A request line is an ASCII text line consisting of three tags: the HTTP Method of the request, the request URL, and the HTTP version. The request line is separated by a blank amount.
Request Header:
HTTP uses an HTTP header to transmit the request metadata. The HTTP header is a value pair separated by a colon. Before the colon, It is the name of the HTTP header, followed by the value of the HTTP header.
Empty rows:
Send carriage return and return, notifying the server that there are no request headers below.
Message Body:
When an HTTP request contains a query string, if it is a get method, query string or form data, and 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 Information:
The HTTP response includes the status line, Response Header, message body, and an empty line that separates the message body 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.
Response Header:
The response header is the same as the request header.
Message Body:
The HTML document to be sent back to the client or other content to be displayed. The web server places the document information sent back to the client in the message body.


Web Server defects:
It can only provide static webpage content to the client.


The earliest solution CGI:
CGI (common Gateway Interface) is process-based.


JAVA solution:
JSP: java server interface technology.
Servlet:
Servlet is a java program running on the WEB server or application server. It is mainly used to generate dynamic content on the Child server.
WEB container:
The container supports Servlet, including communication, lifecycle management, multithreading, JSP, and processing security.
WEB containers are mainly used to provide an environment for the application components (Servlet, JSP) in the container, so that Servlet and JSP can directly interact with the environment variables in the container, in this way, we can focus on processing and implementing the business logic with Servlet, without having to focus on anything else.
Servlet and web Container work together to process requests and responses:
1. The client sends an HTTP request to the server;
2. the HTTP request is received by the server. If the requested static page is processed by the web server and the java web component (Servlet, JSP) is handed over to the WEB container, WEB containers can be started in processes of the same process, different processes, or other WEB Service hosts.
3. The WEB Container determines the specific Servlet class to be called Based on the Servlet configuration file, and passes the request and response objects to it.
4. The Servlet knows who the client user is based on the request object, the client's request information and other information. After the Servlet completes processing, it puts the information to be returned into the response object and returns it to the client.
5. Once the Servlet completes request processing, the WEB Container will refresh the request and return the control to the WEB server.


Composition of java web applications:
Configuration files, static files and JSP files, class files and packages.
Each WEB application must have a WEB-INF directory, a web. xml file, and a classes directory.

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.