Servlet is a piece of Java code that can expand the functions of the Web server. Each Servlet is running in the process, and a new Servlet request is run in the Servlet process as a thread.
The Servlet container is responsible for connecting the Web server and Servlet process. The Servlet is responsible for providing the runtime environment of the Servlet and loading and calling these servlets at the appropriate time. The Servlet container can run in the same process as the Web server, or separately. Even some Servlet containers are Web servers, such as Tomcat.
The Servlet container passes the user's request to the Servlet, and then converts the Servlet response to an http Response Message and returns it to the customer.
Each Servlet process has a Servlet Context. This Servlet Context corresponds to a Web application. Servlet Context is associated with a url path prefix.
Generally, after the Servlet receives a request from the client passed by the Servlet container, it processes some business logic and then writes the html code to the response stream. However, this method makes it difficult to maintain the business logic and the web ui, which makes it impossible for programmers and WEB designers to work separately.