laitimes

Java Web Development Basics 7 Web Terms Analysis

author:Test development just brother

7 web terms

  1. Website: static vs dynamic
  2. HTTP
  3. HTTP Requests
  4. GET vs POST
  5. Servlet Container
  6. Server: Web vs Application
  7. Content Type

Website: static vs dynamic

The content of the website includes text, images, audio, and video, which can be accessed through URLs. Websites are divided into static websites and dynamic websites.

Static websites

Java Web Development Basics 7 Web Terms Analysis

Static websites are written in HTML, and all the content is contained within the web page as if it were printed.

Dynamic website

Java Web Development Basics 7 Web Terms Analysis

Dynamic websites are divided into client and server terminals, and the content can be dynamically changed, and the content of the web page can be dynamically updated according to user requests. Server-side languages include servlets, ASP.NET, and so on.

HTTP

Java Web Development Basics 7 Web Terms Analysis

HTTP is the abbreviation of Hypertext Transfer Protocol, which is located in the application layer (layer 7) of the OSI network layering model.

Hypertext is a form of text that contains not only ordinary text content, but also elements that can be linked to other text or resources. These links are often referred to as "hyperlinks". The concept of hypertext was developed by Ted Nelson in the 1960s and was widely used in the development of the World Wide Web.

HTTP has the following features:

  • media independent:支持任何类型的媒体内容
  • connectionless: No connection, the client disconnects after sending a request
  • stateless: stateless, the server does not retain the state of the client's request, and does not know who is who

HTTP is based on the TCP/IP protocol and establishes a reliable connection through TCP. Why is HTTP connectionless, but reliable, based on TCP? If you want to transfer data reliably, you must have a stable and reliable connection to ensure that the data is not lost, and this connection is a TCP connection. HTTP sends and receives data over a TCP connection.

In HTTP/1.0, a new TCP connection is established for each request, and the connection is closed as soon as the request is completed. In HTTP/1.1, persistent connections were introduced, allowing multiple request/response sessions to take place on the same TCP connection, but each request/response conversation remained independent. HTTP/1.1 is a persistent connection, so can it still be called connectionless? Yes, it's still connectionless. Persistent connections are through

Connection: keep-alive

Header, which allows the connection to remain open for a period of time without the need to re-establish and close the connection. The essence of connectionless is that each request/response conversation is independent, with an emphasis on independence.

HTTP Requests

An HTTP request is a request sent by a client to a server and contains the following contents:

Java Web Development Basics 7 Web Terms Analysis
  • The Request-line(请求行)
  • The analysis of source IP address, proxy and port(源信息)
  • The analysis of destination IP address, protocol, port and host(目标信息)
  • The Requested URI (Uniform Resource Identifier)(链接)
  • The Request method and Content(方法和内容)
  • The User-Agent header(请求头)
  • The Connection control header(请求头)
  • The Cache control header(请求头)

You can use the F12 developer tools to view HTTP request information in your browser.

GET vs POST

GET and POST are the 2 main methods of HTTP requests, and their differences are as follows:

  1. Data Transmission Method
  • GET: Appends the request parameters to the query string of the URL, and the data is transmitted through the URL. For example:

    http://example.com/page?param1=value1&param2=value2

  • POST: Contains the request parameters in the request body, and the data is transmitted through the request body and is not displayed in the URL
  1. safety
  • GET: Because the parameters are displayed in the URL, sensitive information is easily exposed in browser history, log files, etc., so it is not suitable for transmitting sensitive data
  • POST: The parameter is transmitted in the request body, which is relatively more secure, but it does not mean that it is completely secure, and HTTPS is still used to encrypt the data
  1. Data length limits
  • GET: Due to the URL length limit (typically 2048 characters), GET requests have a limited amount of data to transmit
  • POST: There is no obvious data length limit, and a large amount of data can be transferred
  1. Idempotency
  • GET: idempotent, i.e. multiple times the same GET request should produce the same result and will not have side effects on server resources
  • POST: Non-idempotent, i.e. multiple identical POST requests may produce different results, often used to submit data or trigger operations on the server
  1. cache
  • GET: It can be cached by the browser and is suitable for fetching immutable data
  • POST: It is not cached by default and is suitable for submitting data or performing operations
  1. use
  • GET: It is mainly used to request data, such as obtaining web page content and querying information
  • POST: Mainly used to submit data, such as submitting forms, uploading files, etc

Servlet Container

Java Web Development Basics 7 Web Terms Analysis

A Servlet Container is a runtime environment for managing and executing Java servlets. It belongs to Java EE and is responsible for handling client requests, managing the servlet lifecycle, and providing various services such as security, concurrency, resource management, etc.

A servlet container is a part of a web server, and what we often call Apache Tomcat is both a web server (built-in HTTP server) and a servlet container. Capable of handling both static and dynamic content, it provides a complete runtime environment for developing and deploying Java web applications.

Server: Web vs Application

Web servers primarily handle static content and HTTP requests, while application servers primarily handle dynamic content and business logic.

Traditional Web Server:

  • Apache HTTP Server: An open-source web server that is widely used to host static websites and dynamic web applications
  • Nginx: A high-performance web server that is particularly good at handling a large number of concurrent connections, often used for reverse proxy and load balancing

Modern Web Servers:

  • Node.js: A JavaScript runtime environment based on the Chrome V8 engine that uses an event-driven, non-blocking I/O model, making it ideal for building high-performance, scalable web applications
  • Caddy: A modern web server that supports HTTPS by default, is simple to configure, and supports automatic TLS certificate management

Application Server:

  • Apache Tomcat: Although it is primarily a servlet container, it can also be used as a lightweight application server
  • GlassFish: A complete Java EE application server that supports all Java EE specifications
  • JBoss/WildFly: An open-source Java EE application server that provides comprehensive enterprise-grade functionality
  • WebLogic: Oracle's enterprise-grade application server that supports a wide range of enterprise functions
  • WebSphere: An enterprise-grade application server provided by IBM for a wide range of large-scale enterprise applications

In practice, web servers and application servers are often used together, for example:

  • As a front-end web server, Nginx processes static content and forwards dynamic requests to the back-end Tomcat application server for processing
  • Nginx acts as a reverse proxy to receive all requests, process or forward them according to the request type, and send them to Tomcat, the backend application server, and load balancing

A servlet container can be part of a web server, for example, Apache Tomcat is a server that contains both web server and servlet container functions. Tomcat is capable of handling both static content (e.g., HTML, CSS, JavaScript files) and dynamic content (e.g., content generated through servlets).

Servlet containers can also be part of an application server, for example, in an enterprise application server (such as GlassFish, JBoss/WildFly), the application server not only contains the servlet container, but also provides many other enterprise-level functions, such as transaction management, message queues, EJB (Enterprise JavaBeans) support, etc.

+----------------------+ +----------------------+
| Web Server | | Application Server |
| | | |
| +------------------+ | | +------------------+ |
| | Servlet Container| | | | Servlet Container| |
| | (Tomcat) | | | | (GlassFish, | |
| +------------------+ | | | JBoss/WildFly) | |
| | | +------------------+ |
+----------------------+ | |
 | +------------------+ |
 | | Other Enterprise | |
 | | Features (EJB, | |
 | | Transactions, | |
 | | Messaging, etc.) | |
 | +------------------+ |
 +----------------------+
           

Content Type

Content-Type is a header field in the HTTP protocol that indicates the media type (MIME type) of the data sent to the recipient. It tells the client or server how to interpret and process the data in the request or response. Content-Type can be used in both HTTP requests and responses.

常见Content-Type如下:

  1. Text Type:
  • text/html

    : HTML document
  • text/plain

    : Plain text
  • text/css

    : CSS stylesheets
  • text/javascript

    :JavaScript code
  • Application Type:
    • application/json

      : data in JSON format
    • application/xml

      : Data in XML format
    • application/x-www-form-urlencoded

      : Form data, typically used for POST requests
    • application/octet-stream

      : A binary data stream, typically used for file downloads
  • Multi-part type:
    • multipart/form-data

      : Used for form file upload, and the form data can contain files
    • multipart/byteranges

      : indicates that the response contains multiple parts, each of which is a byte range
  • Image Type:
    • image/jpeg

      : JPEG image
    • image/png

      :P NG image
    • image/gif

      : GIF image
  • Audio & Video Types:
    • audio/mpeg

      : MPEG audio files
    • video/mp4

      : MP4 video file

    Resources:

    https://www.javatpoint.com/web-terminology

    ChatGPT

    Read on