Java web environment construction

Table of contents

1. Introduction to Java Web

Second, install the Java runtime environment

1. Java Virtual Machine (JVM)

2. Tools

(1) How to download the compiler:

 (2) Click Download Pakeges

 (3) Select the required version and system

 (4) Click "select Another Mirror" to expand the option chain

 (5) Enter the payment interface, payment is optional or not, if you don’t pay, you can click click here to download directly

3. JDK installation

4. Configure environment variables

Third, build a Java web environment

1. What is Tomcat?

(1) External deployment of Tomcat

(2) Deploy Tomcat in eclipse

2. Create a project

Create a Java web project: the specific steps are file->new->Dynamic Web Project (if not found, click other to find it in the web)

Fourth, install the database

Five, common construction problems

404: A 404 error occurs on the page, maybe your path is wrong or your file does not exist

500: If a 500 error occurs on the page, it means your code is wrong


 

1. Introduction to Java Web

The Java language is an advanced programming language launched by Sun Corporation (Stanford University Network) in the United States in 1995. The so-called programming language is the language of the computer. People can use the programming language to give commands to the computer, so that the computer can complete the functions that people need.

Java Web mainly uses Java technology to solve the technology in the web field, and needs to run on a specific web server. Java Web is cross-platform and can be deployed and run on different platforms. 

To create a Java web, you must first deploy a Java operating environment on your computer. There are four main steps:

  • Install the Java environment
  • Build a web environment
  • Run the web project
  • install database

Second, install the Java runtime environment

1. Java Virtual Machine (JVM)

 JVM (Java Virtual Machine): Java virtual machine, referred to as JVM, is a hypothetical computer that runs all Java programs, is the operating environment of Java programs, and is one of the most attractive features of Java. The Java code we write runs on the JVM. The programs we write run on the JVM, and the JVM runs on the operating system. The JVM itself does not have cross-platform functions, and each operating system has different versions of virtual machines (we commonly have win version, Lin version, and Mac version, which refer to window system, Linux system, and Mac system respectively)

  • JRE (Java Runtime Environment): It is the runtime environment of the Java program, including the core class library required by the JVM and runtime.
  • JDK (Java Development Kit): It is a Java program development kit, including JRE and tools used by developers.

        We want to run an existing Java program, so we only need to install JRE.
        We want to develop a brand new Java program, so JDK must be installed.

2. Tools

Compilers for writing Java web include eclipse, idea, myEclipse, here we choose eclipse

Note: After downloading eclipse, don't rush to open it, because the JDK has not been installed yet. What I have to mention here is that myEclipse comes with JDK, and eclipse needs to install JDK by itself.

(1) How to download the compiler:

Eclipse official website: http://www.eclipse.org/

 

 (2) Click Download Pakeges

 

 (3) Select the required version and system

 

 (4) Click "select Another Mirror" to expand the option chain

 

(5) Enter the payment interface, payment is optional or not, if you don’t pay, you can click click here to download directly

 

 The above is the whole process of installing eclipse

3. JDK installation

Because I am using the JDK8 version, I will show you the 8 version. If you use other versions, you can go to the jdk official website to download it yourself. The official website URL: http://jdk.java.net/

 

 

The following is a demonstration of the installation steps. Note: Do not include spaces and Chinese in the installation path.

 

 

 

 

 

The above are all the steps to install JDK.

4. Configure environment variables

After installing the JDK, configure the environment variables, the steps are as follows:

Control Panel (win+i input control panel) -> System and Security -> System -> Advanced System Settings -> Environment Variables, the icon is shown as follows:

 

 

 

 

 

 Note: After opening the path, the path variable is displayed in windows10 and added separately, otherwise it cannot be recognized

Need to %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

 

 After filling it out, click OK, and the configuration is complete. Next, we test whether the Java runtime environment is configured.

win+r to open the run box

 

 After entering Java -version, the following results are obtained, indicating that the configuration is successful

 

Third, build a Java web environment

1. What is Tomcat?

Tomcat is a core project in the Jakarta project of the Apache Software Foundation (Apache Software Foundation), jointly developed by Apache, Sun and some other companies and individuals. Thanks to Sun's participation and support, the latest Servlet and JSP specifications can always be reflected in Tomcat, and Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications.

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 official website: http://tomcat.apache.org

When we download Tomcat, we need to correspond to the version of JDK. The Tomcat version I use here is 9.0

tip: The downloaded Tomcat does not need to be installed, just put it directly on the disk, not on the desktop.

(1) External deployment of Tomcat

Find the path where the Tomcat folder is stored and open it

 

 Tomcat's directory structure:

  • The bin directory is mainly used to store tomcat commands. There are two main categories, one is .sh ending ( linux command), and the other is .bat ending (windows command).
  • The conf directory is mainly used to store some configuration files of tomcat . server.xml can set the port number, set the domain name or IP , the project loaded by default, and the request encoding.
  • The lib directory is mainly used to store jar packages that need to be loaded when tomcat runs .
  • The logs directory is used to store the log files generated by tomcat during operation
  • The temp directory user stores temporary files generated by tomcat during operation.
  • The webapps directory is used to store applications. When tomcat starts, it will load the applications in the webapps directory. Applications can be published in the form of folders, war packages, and jar packages.
  • The work directory is used to store the compiled files of tomcat at runtime, such as JSP compiled files.

 

 Note here: .bat is for the window system, and .sh is for the Linux system.

After opening, the following interface is displayed, which means that the server has been successfully started.

tip: One thing I have to mention here is that when we open startup.bat, there will be a flash, so we need to test whether the jdk environment variable is correct! You can do the following:

 

 

(2) Deploy Tomcat in eclipse

The specific steps of configuration:

window->Show View->Servers

 

 

 

 

 After completing the above operations, the deployment of Tomcat in eclipse is completed.

2. Create a project

Create a Java web project: the specific steps are file->new->Dynamic Web Project (if not found, click other to find it in the web)

 or

 the effect is the same

 

 

 new jsp

 After successful creation, open index.jsp

 This page is written to be equivalent to HTML code.

 If it is not UTF-8, do the following:

 

 Startup project:

Note: The Java code in jsp should be written in <%%>, otherwise an error will be reported.

 When the following interface appears, it means that the operation is successful

 

Next, open the browser of the computer, enter localhost:8080/project name/index.html in the browser, the project name is the name of the project you created, here we are web00, and the following page index.html is what we just created The test page. Then you can browse in the browser.

The result is as follows:

 The above are all the steps to create a project.

Fourth, install the database

The installation of the database, because the content is too long, I mentioned it in another article. The article path is

https://blog.csdn.net/m0_67376124/article/details/123148172

Five, common construction problems

  • 404: A 404 error occurs on the page, maybe your path is wrong or your file does not exist

  • 500: If a 500 error occurs on the page, it means your code is wrong

So far I have only encountered these two problems, and I will add more problems in the future.

That's all for this sharing, see you next time!

 

Guess you like

Origin blog.csdn.net/m0_67376124/article/details/123700793