Servlet construction and project packaging and deployment to Tomcat (use of Tomcat)

Servlet: A framework/tool, through which the development project (back-end API) can be more convenient, and Request and Response have been encapsulated.

(1) Creation of Servlet
①Create a webapp maven project

Insert picture description hereUntil the project is created.

②Add the source code root directory

Insert picture description hereInsert picture description hereInsert picture description here

③Add servlet reference

When configuring pom.xml, recommended: mvnrepository
Insert picture description hereInsert picture description here the dependency add the code to the dependencies pom.xml in
Insert picture description here

④Configure the servlet configuration file web.xml

Fixed writing in web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1"
         metadata-complete="true">

  <servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>

</web-app>

Insert picture description hereInsert picture description here

(2) The project is packaged and deployed to Tomcat
①Import the jar package to the project, click maven on the right and press the refresh button

Insert picture description hereInsert picture description here

②Check the local project file after the package is successful, find the .war project file that has just been packaged, and select copy.

Insert picture description hereInsert picture description here

③Find and open your own Tomcat file, copy the .war file to the webapps folder, then open the bin directory, click Startup.bat to start Tomcat, open the browser and enter http://localhost:8080/webAppDome/hello, click back You can visit by car.Insert picture description hereInsert picture description hereInsert picture description hereInsert picture description here
④ Then, there is no more. . . Discuss questionable private messages.

Guess you like

Origin blog.csdn.net/qq_47364122/article/details/115283570