JavaWeb detailed explanation plus actual combat

JavaWeb

1. Basic concepts

1.1. Preface

web development

  • web, meaning of web page
  • static web
    • HTML、CSS
    • The data available for all to see is always the same
  • dynamic web
    • The data provided to everyone will always be issued and changed. Everyone sees different information at different times and places.
    • Technology stack: Servlet/JSP, ASP, PHP

In Java, the technology of dynamic WEB resource development is collectively referred to as JAVAWEB

1.2. Web applications

A web application, the part of a program that provides browser access

  • HTML、CSS、JS
  • JSP、Servlet
  • Java
  • jar package
  • Configuration file (properties)

1.3, static web

image-20210915151355826

  • Disadvantages of Static Pages
    • Web pages cannot update dynamics, all users see a page
      • Carousel image, click special effects, pseudo-dynamic
      • JavaScript (most commonly used)
      • VBScript
    • Unable to interact with the database (data cannot be persisted and users cannot interact)

1.4. Dynamic Web

The page will be displayed dynamically, "the effect of web page display varies from person to person".

image-20210915152623525

shortcoming:

  • There is an error in the dynamic web resource added to the server, we need to rewrite our background program
    • Shutdown for maintenance

advantage:

  • Web pages can be updated dynamically, and the page that each user sees is not a page
  • It can interact with the database to ensure data persistence.

2. Explanation of web server

2.1. Common web servers

  • ASP

    • A language created by Microsoft that adds java code to HTML statements

    • <%  java代码%>
      
  • PHP

    • Advantages: fast running speed, good performance, cross-platform, concise code.
    • Disadvantages: It is not suitable for large-scale project development and cannot bear a large amount of data.
  • JSP/Servlet The essence of JSP is Servlet

    • Advantages: It can carry three highs, high concurrency, high availability, and high performance.

Understand: B/S browser/server C/S client/server

2...2, web server

  • IIS
  • tomcat

Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because Tomcat has advanced technology, stable performance, and is free, it is deeply loved by Java enthusiasts and recognized by some software developers, and has become a relatively popular Web application server.

Tomcat server is a free and open source web application server. It is a lightweight application server . It is widely used in small and medium-sized systems and occasions where there are not many concurrent access users. It is the first choice for developing and debugging JSP programs. Tomcat is actually an extension of the Apache server, but it runs independently at runtime, so when you run tomcat, it actually runs as a separate process from Apache.

The trick is that, when configured correctly, Apache serves HTML pages, while Tomcat actually runs JSP pages and servlets. In addition, Tomcat, like web servers such as IIS , has the function of processing HTML pages. In addition, it is also a Servlet and JSP container. The independent Servlet container is the default mode of Tomcat. However, Tomcat's ability to handle static HTML is not as good as the Apache server. Currently the latest version of Tomcat is 10.0.5**. **

Function: It is a passive operation, processing some client requests and making return requests

3、Tomcat

3.1, Tomcat installation and configuration

image-20210915202445569

image-20210915202618098

Note: common problems in tomcat

  • There is a problem with the java environment variable configuration, and there is a flashback phenomenon
  • If there is a flashback, it may be a compatibility problem with the computer you clicked on.
  • Tomcat's Chinese garbled problem

3.2, tomcat file configuration problem

image-20210915202951906

Note: The main core configuration file in tomcat is in the server.xml file under the conf folder

It can configure the port number and the name of the host.

The port number of https is 443 by default

The default port number of mysql is 3306

The default port number of http is 80

  • Its default host name is local host->127.0.01
  • The default website storage location is: webapp

Difficult interview questions

Please tell us how the website is accessible

  • Enter a domain name; hit enter

  • Check whether there is a mapping of this domain name under the hosts folder of the machine

  • If yes, return the corresponding IP address

  • If not, go to the DNS server to find it (domain names all over the world are on it)

4. Configure environment variables

3.3. Publish an external website

You can access the webpage you wrote by placing it under the webapp file in tomcat

The structure a website should have

--webapps:tomcat服务器中的web目录
    -Root
    -网站的项目名称
    	-WEB-INF
    	-classes:java程序
    	-lib:web应用所依赖的jar包
    	-web.xml网站的配置文件
    -index.html 默认的首页
    -static
    	-css
    		-style.-css
    	-js
    	-img

4、HTTP

4.1. Definition of HTTP

http (Hypertext Transfer Protocol), is a simple request-response protocol, usually running on TCP

  • hypertext: html, string
  • Hypertext: pictures, music, location, video...

4.2. Two eras

  • http1.0
    • HTTP/1.0: After the client connects to the web server, it can only obtain one web resource and disconnect
  • http2.0
    • HTTP/1.1: After the client connects to the web server, it can obtain multiple web resources and disconnect

4.3, Http request

  • The client sends a request (Request) to the server
  1. request line

    • Request method in the request line: GET
    • Request method: GET, POST
    • get: The request can carry relatively few parameters, the size is limited, and the content of the data will be displayed in the URL address bar of the browser, which is not safe but efficient
    • post: There is no limit to the parameters that the request can carry, and there is no limit to the size. The content of the data will not be displayed in the URL address bar of the browser. It is safe but not efficient

    2. Message header

    Accept:告诉浏览器所支持的数据类型
    Accept-Encoding:表示浏览器支持的编码格式 GBK UTF-8 GB2312 ISO8859-1
    Accept-Language:告诉浏览器的语言环境
    Cache-Control:缓存控制
    Connection:告诉浏览器请求断开还是保持连接
    Host:表示主机.....
    

4.4, Http response

server – response – client

1. Response body

Accept:告诉浏览器所支持的数据类型
Accept-Encoding:表示浏览器支持的编码格式 GBK UTF-8 GB2312 ISO8859-1
Accept-Language:告诉浏览器的语言环境
Cache-Control:缓存控制
Connection:告诉浏览器请求断开还是保持连接
Host:表示主机.....
Refresh:告诉客户端,多久刷刷一次
Location:让网页重定向

2. Response status code (emphasis)

200: represents the corresponding success

3xx: request redirection

  • Definition of Redirect: You redirect to the new location I gave you

404: Resource not found

  • resource does not exist

5xx: Server code error 500 (most common)

502: Bad Gateway

common interview questions

When you enter the address in the address bar of your browser and press Enter, the page can show what happened afterwards?

5、Maven

5.1. Maven project architecture management tool

Function: to facilitate the import of jar packages

The core idea of ​​Maven: convention is greater than configuration

  • Do not violate constraints. must follow the rules

Maven will stipulate how to write Java, you must follow this specification

5.2. Download and install Maven

Official website: https://maven.apache.org/

image-20210916085008365

5.3, Maven environment configuration

The configuration is as follows

  • M2_HOME: The path is the bin directory under the maven directory
  • MAVEN_HOME: maven's home directory
  • PATH: Configure the bin directory under maven

Whether the test was successful

image-20210916085543684

5.4. Alibaba Cloud Mirroring

  • mirror: mirrors
    • Speed ​​up the download of related packages
  • Aunt Jin in China uses the image of Alibaba Cloud
<mirror>
<id>alimaven</id>
<name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf>
</mirror>

5.5. Local warehouse

build a warehouse

 <localRepository>D:\Maven\apache-maven-3.8.1\maven-repo</localRepository>

5.6. Using maven in IDEA

1. Create a new project

2. Select the Maven project

image-20210917103128734

3. Name the project

image-20210917105023369

4. Choose the location of your own maven file

5. Click the automatic import of the package, and finally show that the import is successful

image-20210917105137007

5.7. Create an ordinary maven project

1. Create a new project first

image-20210917105426246

2. Choose to create a maven project, but do not add any options

image-20210917105603578

image-20210917105637599

5.8. Mark folder

image-20210917105950854

image-20210917110039194

The second method

image-20210917110114268

…(img-rzeZf3eF-1631848031395)]

The second method

[External link image transfer...(img-3UMxsuUS-1631848031396)]

Guess you like

Origin blog.csdn.net/qq_46524280/article/details/120344955