Create a JavaWeb simple project (super detailed, at a glance) - 1

Before writing our simple JavaWeb project, let me introduce the project environment of this project.

This project is a JavaWeb-based development environment, specifically using the following technologies and tools:

  1. JavaWeb: JavaWeb is a Web development technology on the Java platform, which includes Servlet, JSP, JavaBean, JDBC and other technologies.

  2. Servlet: Servlet is a component in JavaWeb, which can receive HTTP requests and respond to HTTP responses, and is the core of Web applications.

  3. JSP: JSP (JavaServer Pages) is another component in JavaWeb, which allows developers to embed Java code in HTML pages to dynamically generate pages.

  4. MyBatis: MyBatis is a Java persistence framework that helps developers access databases more easily using JDBC.

  5. MySQL: MySQL is an open source relational database management system that provides efficient, reliable, and stable data storage and access functions.

  6. Maven: Maven is a Java project management and construction tool that can automatically download dependent libraries, compile code, run tests and other tasks.


Project environment preparation:

I understand the idea

The IDEA version demonstrated in this article is the latest version of 2023.1

JDK and Tomcat

The corresponding relationship between JDK and Tomcat versions is shown in the figure below

Correspondence diagram of JDK and Tomcat versions

In this article, JDK 19 and Tomcat 10.0 will be used for demonstration.

In the installation of JDK and Tomcat, environment variables need to be configured! ! ! Otherwise Tomcat may fail to start.

Configure Tomcat in IDEA

  1. Download and install Tomcat, and start the Tomcat server.
  2. Open the project in IDEA and select "Run" -> "Edit Configurations" in the top toolbar.
  3. Select "Tomcat Server" -> "Local" -> "Configure" in the left panel.
  4. Add the Tomcat installation path in the "Application Server" tab, and click "Apply" to save.
  5. In the "Deployment" tab, click the "+" icon to add your application WAR file or directory. When a WAR file is added, it is automatically unpacked and installed in Tomcat.
  6. Click "OK" to save the configuration.
  7. Now you can start Tomcat in IDEA, select the "Run" -> "Run" option in the menu bar, and select the Tomcat configuration just configured.

If IDEA prompts that the servlet api is not detected after the configuration is complete, you can solve this problem by adding the relevant jar package to the WEB-INF/lib directory.

At this point our preparatory work has been completed, and then we start to create our JavaWeb project step by step.

New Web project

1. Open the IntelliJ IDEA software and select "Create New Project".

2. In the template interface, select "Jakarta EE", some versions are "Java Enterprise".

3. In the "New Project" window, enter the project name, project location, project type and other information, select Template as "Web application", and select the Tomcat just configured, and then click the "Next" button.

 

4. In the "Java EE Version" window, select your application server version and JAVA version. You can choose a default value if you are unsure. Servlet is checked by default, if it is not checked by default, you can also choose manual.

5. Finally click the "Create" button to complete the creation of the Web project.

If it is the first time to create a web project, our IDEA may need to download or load some things, and the creation will be successful after the progress bar is loaded. After the creation is complete, as shown in the figure.

After the creation is complete, IDEA will automatically generate a Servlet and JSP page for us, we can try to run it.

Click the small triangle in the upper right corner to start our Tomcat server.

 

After startup, IDEA will automatically open index.jsp in our default browser.

 

At this point, our first JavaWeb project has been established.

In the next chapter, I will list several common problems during the creation process, as well as some detailed code examples (Servlet requests, connecting to databases, etc.)

Guess you like

Origin blog.csdn.net/z15839280234/article/details/130369696