Create Servlet with IDEA from scratch

①Use version: IDEA 2019.3.5 enterprise version, when using the latest version, the steps will be different from what I wrote.

②Process:
New->Project under File in the upper left corner...
Insert picture description here
In the pop-up window, click Java Enterprise, check Web Application, and click Next.
Insert picture description here
Name the project
Insert picture description here
Right-click under src (or where you want to store the servlet) and select New->Select Create New Servlet

to name the servlet and give the servlet a package name.

After finishing the previous step, the web.xml file will be automatically created, and the contents are as follows.
Insert picture description here
Click Edit Configurations next to the hammer on the upper right side...
Insert picture description here
The following window appears.
Insert picture description here
Click the plus sign in the upper left corner and select Tomcat Server->local.
Insert picture description here
The following window appears. Click Configure...
Insert picture description here
The following window appears, click the folder icon next to Tomcat Home and click the folder icon next to Tomcat base directory. And choose the download path to your Tomcat. And click OK.
Insert picture description here
Click Fix at the bottom right.
Insert picture description here
Click on the place as shown in the picture.
Insert picture description here
After the above figure is executed, it will look like the figure below.
Insert picture description here
After all the above is done, click on the Servlet file you created. Enter the code shown in the figure below.
Insert picture description here
Write the full mapping relationship under web.xml.
Insert picture description here
Click the green triangle in the upper right corner to run Tomcat.
Insert picture description here
The browser automatically jumps to the index.jsp file by default. Then enter the text in the url-pattern in the mapping relationship under the address bar.
Insert picture description here
It was found that IDEA output nihao, indicating that the Servlet was created successfully.
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45715461/article/details/114887265