Web project deployment environment construction: JDK + Tomcat + IDEA
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:
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/
When the download is completed, it will look like this:
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
② Find the advanced system settings. It is normal for different Windows versions to have different interfaces.
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.
Find Path
variable name 2: PATH
Variable value 2: Create two new paths: %JAVA_HOME%\bin
, %JAVA_HOME%\jre\bin
Variable name 3: CLASSPATH
Variable value 3:
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME\lib\tools.jar;%CATALINA_HOME%\lib\servlet-api.jar
1.3 Check if the installation is successful
Win+r, enter cmd
in the command line window and press java -version
Enter. If the version information of jdk can be displayed, the configuration is successful
(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
the download is completed, it will look like this:
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.
If you do not create this variable, an error will be reported when starting tomcat.
②Path new path
New path: %CATALINA_HOME%\bin
,%CATALINA_HOME%\lib
2.3 Check if the installation is successful
Win+r Enter cmd
command line input: startup.bat
This appears to prove that it has been installed
, but there is also a garbled problem:
Solution:
Find in the folder: apache-tomcat-9.0.45 → conf → logging.properties
Open it with Notepad
and find it :
Change to: java.util.logging.ConsoleHandler.encoding =GBK
Then the display will be normal.
Note: Tomcat窗口不能关闭!
At this time, enter on the browser http://localhost:8080/
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/
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 .
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
②Add dependencies to the project first.
First, right-click the project you created, then click add framework support
to check Web application, and then click ok
. 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.
② Configuring Tomcat
IDEA is very smart and can actively find the local tomcat. If you can’t find it, click configure to add it manually
. First click deployment, and configure your own project name first, which is the name of the project for external access.
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
external access path, which can be set to be consistent with the project name and
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).
After configuring, apply first and then ok.
If an error occurs:
Solution: Reference
Open the project in the browser:
the web page is displayed as:
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
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
This will connect to MySQL
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
②Open the database
③Create a new table.
Create as many as you like. Save the table. The table on the left will have the name of the table you created.
Fill in the data.
4.2.3 Query
Query statement: SELECT 列名称 FROM 表名称
For example:SELECT * FROM idpass WHERE id=1
4.2.4 Addition, deletion and modification
Still using the query interface
statement:
①INSERT INTO 表名称 VALUES (值1, 值2,….)
②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.
②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’;