Web project deployment environment construction: JDK + Tomcat + IDEA +MySQL


I always have to pay back when I go out to work. I remember that after four years of undergraduate study, I didn’t like Java and web back-end. After I mastered the front-end Html, css, and JavaScript to a acceptable level, I always hugged the big guys’ thighs in group assignments, and they took me with them. fly. In this way, I passed all the practical courses of my undergraduate degree. Although programming languages ​​are also used at the graduate level, object-oriented and various algorithmic programming cannot be avoided, but the language was changed to C++ and Python, which required everyone to start from scratch. After my senior brother saw all kinds of magical and low-level mistakes on my part, he was speechless but he would help me correct them, so it was okay.
However, now I have to lower my head and wake up in order to graduate! ! ! Now there are no thighs for you to hug, so you still have to face JAVA, JAVA is watching you.

Today, with the mentality of "Hmph, a small Java environment, no matter how troublesome it is, can it be more troublesome than building a deep learning environment?", I was hit hard by reality. "Hmph, sample, there was a popular saying at the time, 'a cup of tea, a pack of cigarettes, an environment matching A day's not a day in vain." Then I matched the environment for the day.

1.java JDK

Reference blog: [1] , [2]
Note that the order of environment construction is first JDK, then Tomcat, and finally IDEA. If Tomcat is installed first, it will report that there is no java environment when verifying its successful installation, as shown below:
Insert image description here

JDK is a software development kit for the Java language. JDK is the core of the entire Java development. It includes the JAVA runtime environment (JVM+Java system class library) and JAVA tools.

1.1 Download and install

Official website: https://www.oracle.com/java/technologies/downloads/
Insert image description here
When the download is completed, it will look like this:
Insert image description here
Click Install, change the path, it is best not to put the c drive, just go to next.

1.2 Configure environment variables

① Right-click on this computer → Properties
Insert image description here
② Find the advanced system settings. It is normal for different Windows versions to have different interfaces.
Insert image description here
Insert image description here
Click the "New" button, and in [System Variables], set three environment variables respectively, namely:
Variable Name 1: JAVA_HOME
Variable Value 1: The absolute path of the JDK installation on the computer.
Insert image description here
Find Path
Insert image description here
variable name 2: PATH
Variable value 2: Create two new paths: %JAVA_HOME%\bin, %JAVA_HOME%\jre\bin
Insert image description here
Variable name 3: CLASSPATH
Variable value 3:

.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME\lib\tools.jar;%CATALINA_HOME%\lib\servlet-api.jar

Insert image description here

1.3 Check if the installation is successful

Win+r, enter cmd
Insert image description here
in the command line window and press java -versionEnter. If the version information of jdk can be displayed, the configuration is successful
Insert image description here
(quietly complain, the more updated Windows 11 is, the more similar the interface will be to Linux, and the Windows characteristics will be lost)

2. TomCat

Reference: [1]

2.1 Download and install

Official website: http://tomcat.apache.org

Which version to download depends on your mood. If you don’t know which one to choose, just choose the latest one. When
Insert image description here
the download is completed, it will look like this:
Insert image description here
Just unzip it to the folder you prepared.

2.2 Configure environment variables

How to find environment variables has already been mentioned in 1.2, so I won’t repeat it here.

① Create a new variable.
Variable name: CATALINA_HOME
Variable value: Path to the decompressed folder.
Insert image description here
If you do not create this variable, an error will be reported when starting tomcat.
Insert image description here

②Path new path
New path: %CATALINA_HOME%\bin,%CATALINA_HOME%\lib
Insert image description here

2.3 Check if the installation is successful

Win+r Enter cmd
command line input: startup.bat
Insert image description here
This appears to prove that it has been installed
, but there is also a garbled problem:
Insert image description here
Solution:
Find in the folder: apache-tomcat-9.0.45 → conf → logging.properties
Open it with Notepad
Insert image description here
and find it :
Insert image description here
Change to: java.util.logging.ConsoleHandler.encoding =GBK
Then the display will be normal.
Insert image description here
Note: Tomcat窗口不能关闭!
At this time, enter on the browser http://localhost:8080/
Insert image description here
and the page will look like this, and the installation will be successful.

3.IDEA

Reference: [1]

3.1 Download and install

Official website: https://www.jetbrains.com/
Insert image description here
After I downloaded the free community version, I found that I couldn’t connect to it. There was no Application Servers and I couldn’t find tomcat-related information on the plugins. I learned on this blog that the community version does not support tomcat. You need to download the professional version .
Insert image description here

30 days is not enough: This method was found on the B station page (it is easy to use in personal testing)

3.2 IDEA deploys Tomcat

Reference: [1]

①Create an ordinary java project
Insert image description here
Insert image description here
②Add dependencies to the project first.
First, right-click the project you created, then click add framework support
Insert image description here
to check Web application, and then click ok
Insert image description here
. We can find that there is an additional web folder. Inside this web folder is the For your own web files, such as html files, jsp files, etc., the web.xml in the WEB-INF directory under the web is used to configure this web project. Under WEB-INF, we generally create a lib folder for storage. jar packages required for the project.
Insert image description here
② Configuring Tomcat
Insert image description here
Insert image description here
Insert image description here
IDEA is very smart and can actively find the local tomcat. If you can’t find it, click configure to add it manually
Insert image description here
. First click deployment, and configure your own project name first, which is the name of the project for external access.
Insert image description here
Click the + sign and select the publishing method (Chapter 2) One option is the war package, the second option is the source code), we select the Artifact
Insert image description here
external access path, which can be set to be consistent with the project name and
Insert image description here
return to the serve interface. Set the following 2 options to hot loading, which means that it will take effect after we modify the file (it will take effect after modifying the java file and it will take effect after re-publishing it).
Insert image description here
After configuring, apply first and then ok.
Insert image description here
If an error occurs:
Insert image description here
Solution: Reference

Open the project in the browser:
Insert image description here
the web page is displayed as:
Insert image description here
Visit this URL, the default access is the index.jsp file below http://localhost:8080/tomcat/

At this point, the web project has been successfully deployed in idea, tomcat has been configured, and the server can be started to run normally.

4.MySQL

4.1 Download and install

Installation version reference: This blogger writes so well that I don’t need to repeat it. However, this blogger uses the installation version, which may cause many problems (reminder from my junior). For the
installation-free version, you can refer to this blog. After
Insert image description here
Insert image description here
installing MySQL, it is inconvenient to use the database directly. Therefore, I plan to install the database graphical interface tool Navicat. For permanent use, refer to: This blogger has a great conscience. For
usage, refer to this blogger.

4.2 Use of Navicat

4.2.1 Link to MySQL

Insert image description here
Insert image description here
This will connect to MySQL
Insert image description here

When the link is closed, the icon will turn gray. When you right-click and open the link, the icon will turn green again.

4.2.2 Create a new table

Reference: [1]
① Create a new database
Insert image description here
Insert image description here

②Open the database
Insert image description here
③Create a new table.
Insert image description here
Create as many as you like. Save the table. The table on the left will have the name of the table you created.
Insert image description here
Fill in the data.

Insert image description here

4.2.3 Query

Insert image description here
Query statement: SELECT 列名称 FROM 表名称
For example:SELECT * FROM idpass WHERE id=1

Insert image description here

4.2.4 Addition, deletion and modification

Still using the query interface
statement:
INSERT INTO 表名称 VALUES (值1, 值2,….)

Insert image description here
Insert image description here

②Note INSERT INTO table_name (列1, 列2,…) VALUES (值1, 值2,….)
:
1. Fields and values ​​must correspond one to one!!! .
2. If the value is a numeric type, you do not need to add quotation marks. If it is a non-numeric type, you need to add quotation marks.
In MySQL, if the data type does not correspond, forced conversion will be performed. When converting a string to a value, if the conversion cannot be performed, the value will be forced to 0.

Insert image description here

Insert image description here
②Delete
statement: DELETE FROM 表名称 WHERE 列名称 = 值
Example:DELETE FROM renshi WHERE id = ‘1’;

③Change
the sentence: UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
Example:UPDATE renshi SET id = ‘123’ WHERE id = ‘1’;

Guess you like

Origin blog.csdn.net/Cream_Cicilian/article/details/129209593