the necessary servlet to the pit(O (∩_∩) o ha! )
Two questions: what is it? How to use it?
The first question:what?
The servlet is a technology that Sun offers to develop dynamic Web resources, and Sun provides a servlet interface in its API. This can be understood as the native servlet is an interface, referring to the interface, we should think that we have to implement it in order to be used by us, servlet this interface is no exception, conceptually, the servlet refers to the Sun company provides this API interface, the convention commonly known, The servlet we're talking about now refers to the class that implements this interface, and the servlet we're talking about is the servlet we're implementing.
Ok the first question is done, the servlet is an interface, and the servlet we normally refer to is the class that implements the interface. (one sentence is done)
The second question:how?
Here, let's talk about the purpose of the servlet, who is using it? Servlet is a small program running on the server (from Baidu Encyclopedia), is the server in use it, servlet=service+applet,service refers to the service, applet refers to small programs, servlet refers to the service applet. ( all servlets below refer to the Servlet applet that implements the Servlet interface )
Next, let's talk about how the servlet uses it,
It is roughly divided into 5 steps, followed by a detailed explanation of each step.
The Servlet applet is called by the server after the server receives a servlet access request from the client:
The ① server first checks if the instance object of the servlet has been loaded and created for the first time. If it is, execute step ④ directly, otherwise, step ②.
② mounts and creates an instance object of the servlet.
③ invokes the Init () method of the Servlet instance object.
④ creates a HttpServletRequest object that encapsulates the HTTP request message and a HttpServletResponse object that represents the HTTP response message, and then calls the servlet's service () Method and passes the request and response objects in as parameters.
Before the ⑤web application is stopped or restarted, the servlet engine uninstalls the servlet and calls the servlet's Destroy () method before uninstalling.
The first step: Typically, the server makes a request to the browser to create only one Servlet object, which is kept in memory and responds to requests made by subsequent browsers until you close the page or call the Servlet method to exit, for the first time, it means you open the page, Until close, exit the browser, and the corresponding Servlet object will call the Destory () method to destroy the corresponding Servlet object.
Step two: Create a corresponding Servlet object
The third step: the initialization method of the calling object,
Fourth: Create a Request object (HttpServletRequest) and Response object (HttpServletResponse) from the Web container (the service program that invokes the Servlet applet), invoke the service () method of the Servlet applet, and the request object and the response object just created as parameters into the process, please note that read and write information about who, black represents the process of the request, blue represents the process of response (picture is too ugly, please forgive me!)
Write down today what the servlet is roughly about and how it's used, next time we're going to say a few methods included in the Servlet applet (init (), destory ();d oget (), Dopost ();
The shortcomings of the welcome to correct, greatly appreciated!
The Java web servlet