Java Web applications are used to create dynamic Web sites

Java provides support for Web applications through servlets and JSPS

Two architectures

C/S (Client/Server), Client Server architecture

B/S (Browser/Server), Browser Server architecture

  1. Development and maintenance costs: C/S development and maintenance costs are higher than B/S because each piece of software on the client needs to be upgraded and maintained, whereas B/S only needs to maintain the server program

  2. Client load: C/S load is heavy, because the client is not only responsible for user interaction, but also needs to send requests to the server, etc. B/S puts transaction logic processing in the server, the client is only responsible for display.

  3. Security: C/S has high security, while B/S has low security due to the large number of users

  4. Scope: C/S applies to LAN, B/S applies to WAN

Web Server and Web Client

A Web server is software that can process client requests and send responses back to the client, running on some physical computer and listening for client requests on a specific port. Such as Apache Tomcat, etc.

A Web client is a piece of software that communicates with a server. Some of the most widely used Web clients are Firefox, Google Chrome, Safari, etc. When we request something from the server via a URL, the Web client is responsible for creating the request and sending it to the server, then parsing the server response and presenting it to the user.

HTTP, HTML, URL

HTTP and HTML

Web server and Web client are two separate pieces of software, so they need to use a common language and a common communication protocol to communicate.

HTML (Hypertext Markup Language) is the common language between the server and the client.

HTTP (Hypertext Transfer Protocol) is a communication protocol between a server and a client,

HTTP:

  • Works on C/S architecture, transferring hypertext from WWW: World Wide Web server to local browser (client).
  • Based on TCP/IP communication protocol

Common transport protocols:

  • HTTP hypertext transfer protocol, which can transfer media resource files (or stream files) and XML data in addition to text. The default port number is 80
  • HTTPS more secure HTTP, generally involving payment websites use HTTPS protocol (s: SSL encryption transmission), the default port number 443
  • FTP file transfer protocol (usually used to upload local resources to the server). The default port number is 21

URL

URL, Universal Resource Locator Used to locate servers and resources. Every resource on the network has its own unique address. Take an example of a fake URL:

  • https://space.bilibili.com:443/20692606/favlist?fid=80026506&ftype=create
  • https://– Communication protocol
  • space.bilibili.com– The DOMAIN name is resolved into an IP address by the DNS server
  • : 443– The port number ranges from 0 to 65535. Port numbers are used to distinguish different items on the same server
  • /20692606/favlist– Requested resource path name
  • ? fid=80026506&ftype=create– Question mark parameter transmission information
  • #zhenyu– HASH value can also be used for information transmission, anchor location, and route control based on HASH (different HASH values display different components and modules)

HTTP workflow

After entering the URL in the browser

  1. The browser requests the DNS server to resolve the IP address corresponding to the domain name in the URL.

  2. After the IP address is resolved, a TCP socket connection is established with the server based on the IP address and port number.

  3. The browser sends an HTTP request to read the file (the file following the domain name in the URL). The request packet is sent to the server as the data in the third TCP three-way handshake packet. A request packet consists of the request line, the request header, the blank line, and the request data.

  4. The Web server parses the request and locates the requested resource. The server writes the resource copy to the TCP socket, which is read by the client. A response consists of a status line, a response header, a blank line, and response data.

  5. Release the TCP connection. If the Connection mode is close, the server actively closes the TCP connection, and the client passively closes the connection. If the Connection mode is Keepalive, the connection is kept for a period of time, during which requests can be received.

  6. The client browser first parses the status line to see the status code indicating whether the request was successful. Each response header is then parsed, and the response header tells the following several bytes of HTML document and the document’s character set. The client browser reads the response data HTML, formats it according to the HTML syntax, and displays it in the browser window.

The HTTP message

A request packet consists of request line, header, blank line, and request data.

The response message also consists of four parts: status line, message header, blank line, and response body.