IDEA2023.1.3 Create a Java Web project and configure Tomcat (fool's tutorial)

This tutorial is only for creating and configuring Tomcat for the Java Web project of IDEA2023.1.3 version, and does not include the Tomcat download tutorial.

1. Select New Project, set the project name and JDK, and click Create

 2. Open Project Structure

3. Click the plus sign in Modules to select Web, so IDEA will help us create the webapp folder and web.xml configuration file

4. Create a web application artifact for the project. IDEA will prompt here. Just click Create Artifact to automatically configure it.

 5. The created page looks like this, just click Apply and OK.

 Current file structure

6. Click Edit Configuration here, it is also available in the Run tab of the navigation bar, the same

 7. Click the + sign to add a Tomcat Server. Pay attention to select Local and Remote.

 8. The addition is like this. If you don’t understand the settings inside, don’t change them randomly. I won’t explain them one by one here. Note that I use port 80. The default is 8080. You don’t need to change it to the same as mine. We need to deploy the newly built Web Artifact to Tomcat. You can click Fix in the lower right corner to let IDEA automatically configure it.

 You can also manually configure it in the Deployment tab, + sign, Artifact

 That's OK

 You should have discovered that the JRE is empty just now. Note that the JRE here will automatically follow the deployed project, so I didn’t talk about it just now. Now click Apply and OK.

 9. Finally, you need to import related dependencies. There are two ways here. Import in the Libraries of Project Structure, click the + sign, Java, and then select the jar package or directory to be added. IDEA will import all the jar packages in the directory , I usually directly choose the lib directory under Tomcat, which contains most of the basic jar packages, such as the servlet-api we want to use.

 You can also put the jar package in the webapp directory, right-click Add as Library, and click OK.

 10. Now that everything is ready, we can finally use Servlet. Write a Servlet and test it.

 Tomcat, start!

Undoubted success 

Take a look at the effect

 It is completely in line with expectations. At this point, a JavaWeb project using Tomcat has been created and can be used. By the way, the resources in the WEB-INF directory are inaccessible. Don’t put things around. So the jar package just now can be accessed and downloaded in the browser.

Finally, the version comparison table from the Apache Tomcat official website is attached. Incompatible versions are likely to cause errors!

The demonstration uses Web4.0, Tomcat9.0.78, and JDK1.8. You can see that they correspond correctly to the table.

Friends who find it useful can like and save it, thank you all.

Guess you like

Origin blog.csdn.net/spd117/article/details/131785183