JavaWeb
1. Basic concepts
web development
-
Static web
- html css
- Provide it to everyone to see that the data will never change
-
Dynamic web
-
Taobao is almost all websites
-
The data provided to everyone will change, and everyone will see different information at different times and places
-
Stack technology; Servlet/JSP ,ASP,PHP,
-
In Java, the development technology of dynamic web resources is collectively referred to as Javaweb
1.2 Web application
web application: a program that can provide browser access;
- a.html b.html... Multiple web resources that can be accessed externally and provide services to the outside world
- Any page or resource you can access exists on the computer somewhere at this time
- URL: to access resources
- The same web resource will be placed in the same folder, web application - > Tomcat: server
- A web application consists of many parts (static web, dynamic web)
- html,css,js
- jsp,servlet
- java program
- jar package
- Configuration files (Properties)
After the web application is written, if you want to provide access to the outside world, you need a server to manage it uniformly
1.3 static web
- *. html, if these things always exist on the server, we can read them directly
- Static web has disadvantages
- The Web page cannot be updated dynamically. All users see the same page
- Rotation chart, click feature: pseudo dynamic
- JS
- He can't protect the database, data can't be persistent, and users can't interact
1.4 dynamic Web
The page will be displayed dynamically
shortcoming
- If there are errors in the dynamic Web resources of the server, we need to rewrite our background program and publish it again
- Shutdown maintenance
2. Web server
2.1 technical introduction
ASP
- What Microsoft did: the first popular ASP in the new year
- Embed VB script in HTML, ASP+COM
- In ASP development, there are thousands of lines of business code in a page, and the page is extremely chaotic
- High maintenance cost
- C#
- IIS server
PHP
- PHP development is fast, powerful, cross platform, and the code is very simple
- Unable to carry large traffic (limitations)
JSP/Servlet
B/S browser and server
C/S client and server
- B/S architecture mainly promoted by sun company
- Based on java language (all large companies or some open source components are written in java)
- It can bear the impact of three high problems (high concurrency, high availability and high performance)
- Syntax like ASP, strengthen market intensity
2.2 Web server
Server is a passive operation, which is used to process some requests of users and give users some response information
IIS
Microsoft: ASP, which comes with Wnidows
Tomcat
3. Tomcat
3.1 Tomca installation
3.2 Tomcat startup and configuration
Folder function
Startup and shutdown
Possible problems
- java environment variables are not configured
- Flash back problem: you need to select the appropriate version
3.3 configuration
The port number of startup can be configured
- tomcat 8080
- mysql 3306
- http 80
- https 443
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
Host name that can be configured for startup
- The default host name is localhost - > 127.0.0.1
- The default location of web apps is webapps
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
Difficult interview questions
Please talk about how the website is accessed!
-
Enter a domain name and press enter
-
Check whether there is a mapping of this domain name under the local C:\Windows\System32\drivers\etc\hosts configuration file
- There is a direct return of the corresponding IP address
- No: go to the DNS server to find it and return it if found, and return it if not found
3.4 publish a Web site
- Put the website written by yourself under the specified web apps folder in the server (Tomcat), and you can access it
Website structure
--webapps: -ROOT -ybl -WEB-INF -classes:java program -lib: web Since the application jar package -web.xml Site profile -index. html default page -static -css -style.css -js -img
4. HTTP
4.1 what is HTTP
HTTP hypertext transfer protocol is a simple request response write one, which usually runs on TCP
- Text: html, string
- Hypertext: picture, music, video, location, map
4.2 two times
- http1.0
- HTTP/1.0: in the early years, after the client could connect to the web server, it could only obtain one web resource and disconnect
- http2.0
- HTTP/1.1: after the client can connect with the web server, it can obtain multiple web resources 4.3
4.3 Http request
- Client – request – server
Baidu as an example
Request URL: https://www.baidu.com / request address Request Method: GET get method /post method Status Code: 200 OK Status code Remote Address: 36.152.44.96:443 Referrer Policy: strict-origin-when-cross-origin
Request method:
- The parameters carried by the GET request are relatively few, and the size is limited. The data content will be displayed in the URL address bar of the browser, which is unsafe but efficient
- There are no restrictions on the carrying parameters and size of the POST request, and the data content will not be displayed in the URL. It is safe but inefficient
4.4 Http response
- Server – corresponding – client
Baidu
2. Corresponding status code
200: request succeeded
3 * *: request redirection
4 * *: resource 404 Not Found
5 * *: server code error 500 502: gateway error
5. Maven
Why should I learn this technology
-
In Java Web development, we need to use a large number of jar packages, which we import manually
-
How can I make something automatically import and configure this jar package for me
Thus Maven was born
5.1Maven project architecture management tool
At present, we are using to import jar packages.
Maven's core idea: Convention is greater than configuration
- There are constraints. Don't break them
Maven will specify how you should write our Java code. You must follow this specification
5.2 download and install Maven
Official website: https://maven.apache.org/
5.3 environment variable configuration
In our system environment variables
to configure
- M2_ bin directory under home Maven directory
- MAVEN_ Directory of home maven
- Configure% Maven in the path of the system_ HOME%\bin
5.4 Alibaba cloud image
//shift+tab format code
<mirror> <id>aliyunmaven</id> <mirrorOf>central</mirrorOf> <name>Alibaba cloud public warehouse</name> <url>https://maven.aliyun.com/repository/central</url> </mirror> <mirror> <id>repo1</id> <mirrorOf>central</mirrorOf> <name>central repo</name> <url>http://repo1.maven.org/maven2/</url> </mirror> <mirror> <id>aliyunmaven</id> <mirrorOf>apache snapshots</mirrorOf> <name>Aliyun Apache warehouse</name> <url>https://maven.aliyun.com/repository/apache-snapshots</url> </mirror>
5.5 local warehouse
Local warehouse
Establish a local warehouse:
<localRepository>D:\Maven\apache-maven-3.8.1\maven-repo</localRepository>
5.6 using Maven in IDEA
- Open IDEA
- Create a Maven project
-
Wait until the project is automatically imported
-
Look what's in the warehouse
-
Maven settings in Idea need to take a look at the settings
-
Here Maven is successfully configured and used in Idea.
5.7 create a normal Maven project
5.8 marking folder function
5.9 configuring Tomcat in IDEA
-
Resolve warning issues,
Why is there this problem? When we visit a website, we need to specify a folder
5.10 Pom file
pom.xml is the core configuration file of Maven
<?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> <!-- Here we explain what we just configured GAV--> <groupId>com.ybl</groupId> <artifactId>javaweb-01-maven</artifactId> <version>1.0-SNAPSHOT</version> <!-- package Packaging method of the project jar:java application war:javaweb application--> <packaging>war</packaging> <name>javaweb-01-maven Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <!-- to configure--> <properties> <!-- Project default build code--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- Compiled version--> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <!--Project dependency--> <dependencies> <!-- Specific since jar Package configuration file--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- Maven The high level of is that he will help you import this Jar Others on which the package depends jar package--> <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.5</version> </dependency> </dependencies> <build> <finalName>javaweb-01-maven</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
Maven's agreement is greater than the configuration. We may encounter the problem that the configuration file we wrote cannot be exported or take effect later. Solution:
<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>