[JavaWeb] Introduction to Java Web, tomcat server, HTTP and maven

1, Java Web

1.Web development
web: web pages, such as https://www.baidu.com
(1) Static web: the data and pages provided will never change;
Technology stack: html, css
(2) Dynamic web: the data and pages provided will always change;
Technology stack: Jsp, servlet, ASP, PHP
Almost all websites are dynamic web, such as Taobao.
2.web application
web application: an application that can be provided for browser access
A web application consists of many parts (static and dynamic web): html, css, Jsp, servlet, Java program, jar package
Configuration files (Properties), etc.
After the web application is written, if you want to provide access to the outside world, you need a server to manage it uniformly
3. Static web

Disadvantages of static web:
① The Web page cannot be dynamically updated. All users see the same page
Rotation chart, click special effect: pseudo dynamic
② It cannot interact with the database (data cannot be persisted, and users cannot interact)
4. Dynamic web
In Java, the technology of dynamic web resource development is collectively referred to as JavaWeb

Advantages: it can be refreshed dynamically and persisted
Disadvantages: downtime update

2, Web server

1. Technical description

1.ASP
Embedded VB script in HTML, ASP + COM
In ASP development, the amount of code is relatively large, the page is extremely chaotic, and the maintenance cost is high
2.PHP
PHP development is fast, powerful, cross platform, and the code is very simple
Unable to carry large traffic (limitations)
3.JSP/Servlet
B/S: browse and server
C/S: client and server
sun company mainly promotes B/S architecture
Based on Java language, it can carry three high (high concurrency, high performance and high availability)

2. Server

Server: a computer that manages computing resources, which is used to process some user requests and give users some response information.
1.lIS server
Microsoft's, ASP... Windows comes with its own server.
2.tomcat server
tomcat official website

Super detailed tomcat download, installation and configuration tutorial
Is a free open source Web application server, which belongs to lightweight application server
The website written by yourself can be accessed through the server by putting it under the specified web application folder (webapps) in the server (Tomcat).

Default port number of tomcat: 8080; Core configuration file: server xml

3, HTTP

1.HTTP
Hypertext Transfer Protocol (HTTP) is a simple request response protocol, which usually runs on TCP.
Function: specify the information transfer Specification between WWW server and browser
Text: html, string
Hypertext: picture, music, video, location, map
Default port: 80
Hypertext Transfer Protocol over securesocket layer (HTTPS) ensures the security of the transmission process through transmission encryption and identity authentication on the basis of HTTP.
Function: secure data transmission
Default port: 443
2. Two times
HTTP 1.0: after the client connects to the web server, only one web resource can be obtained. Disconnect
HTTP 1.1: after the client connects with the web server, multiple web resources can be obtained.
3.Http request
Client - > send request - > server

//Visit Baidu Encyclopedia request
Request URL: https://baikebcs.bdimg.com/baike-icon.png 	// Request address
Request Method: GET	//get/post method
Status Code: 304 //Status code 304
Remote Address: 111.19.219.38:443	//Remote address
Referrer Policy: unsafe-url

(1) Request line

Request method in request line: POST
 Request method: GET/POST
GET: The request can carry fewer parameters with limited size, which will be displayed in the browser URL The address bar displays the data content, which is efficient but unsafe
POST: There are no restrictions on the parameters that can be carried by the request, the size is not limited, and will not be displayed in the browser URL The address bar displays the data content, which is safe but not efficient

(2) Message header

Accept: Tell the browser what data types are supported
Accept-Encoding: Coding format
Accept-Language: Language environment
Connection: Disconnect or connect
Cache-Control: Cache control
Host: host

4.Http response
Server - > response - > client

Cache-Control: private	//Cache control
Connection: keep-alive	//connect
Content-Encoding: gzip	//code
Content-Type: text/html;charset=utf-8	//Coding format

(1) Responder

Accept: Tell the browser what data types are supported
Accept-Encoding: Coding format
Accept-Language: Language environment
Connection: Disconnect or connect
Cache-Control: Cache control
Host: host
Refresh: How often do I refresh
Location: Tell the page to relocate

(2) Response status code

//Common status codes
200 - Request succeeded
301 - Resources (web pages, etc.) are permanently transferred to other URL(Redirect)
404 - The requested resource (web page, etc.) does not exist
500 - Server internal error

Responses are divided into five categories: information response (100 – 199), successful response (200 – 299), redirection (300 – 399), client error (400 – 499) and server error (500 – 599):

Common interview questions:
When you enter the address in the address bar of your browser and press enter, what happened when the page can be displayed back?

4, maven

Maven official website

Uninstallation, reinstallation and configuration of super detailed maven
Apache Maven is a (especially Java programming) project management and automatic build tool, which can easily add dependencies online and download jar packages.
maven's core idea: Convention is greater than configuration

convention over configuration, also known as programming by convention, is a software design paradigm, which aims to reduce the number of decisions that software developers need to make and obtain simple benefits without failure. (Baidu Encyclopedia)

① Project structure of Maven file:

② Label the normal folder as:

③ Structure of maven:

④ pom.xml description

<?xml version="1.0" encoding="UTF-8"?>
<!--maven Version and header files-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--Configured at the beginning of the project GAV-->
    <groupId>com.jd.javaweb</groupId>
    <artifactId>JavaWeb_demo1</artifactId>
    <!--Packing method:① jar: ordinary java;② war: javaweb project-->
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <!--Project dependency-->
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!--maven The strength of is that it will automatically help you import this jar Other package dependencies jar package-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.1</version>
        </dependency>
    </dependencies>
</project>

⑤ Since maven's convention is greater than the configuration, we can encounter the problem that the configuration file we wrote cannot be exported or take effect. Solutions

<!--maven Because its convention is greater than the configuration, we can encounter the problem that the configuration file we wrote cannot be exported or take effect. Solutions-->
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

⑥ The tree structure directory on which the idea operation depends

After creating the maven project, you can click to view the tree structure formed by the jar packages that the project depends on. The strength of maven is that it will automatically help you import other jar packages that this jar package depends on. (third floor and below)

Keywords: Java Front-end server

Added by dudejma on Wed, 22 Dec 2021 10:47:07 +0200