When sending a client request, call the service method and pass a request and response object. Servlet first checks whether the request is a get operation or a post operation. Then it calls the following method: doget or dopost. Both doget and dopost accept requests (httpservletrequest) and responses (httpservletresponse ).
Servlets is a Java class that can use print statements to generate dynamic HTML content. However, it must be mentioned that servlets runs in a container and APIs manages the session and object lifecycle. Therefore, when using Servlets, you can gain all the advantages of the Java platform, including sandbox (Security), database access API through JDBC, and Server Load balancer with cross-platform portability.
JSP pages are actually web pages with traditional HTML and Java code. When calling a JSP page, it is first compiled into a Java Servlet (through the JSP engine. In this case, the servlet engine processes the servlet just like any other servlet. Then, the servlet engine loads the servlet class (using the Class Loader) and executes it to create dynamic HTML and send it to the browser, as shown in 1. The servlet creates all required objects, writes all objects to the output stream as strings, and displays them in the browser.