|
1, Servlet life cycle:
Servlet loading, loading, service and destroyed.
2, the typical function explanation:
Init (): This function is used to initialize the Servlet object. In the Servlet life cycle Servlet function is performed only once.
Destroy (): This function is used to destroy the Servlet object Similarly, Servlet life cycle Servlet function is performed only once.
Service (): This function is to respond to customer requests Servlet objects when in use. Is the core function of the Servlet. There are two parameters: HTTPRequest, HTTPResponse. HTTPServlet already has Service method, the default service function is to call and request a consistent approach do function.
3, tomcat and Servlet is how it works:
Web client makes a request to the Servlet container (tomcat)
Tomcat receives a request
Servlet container creates a HTTPRequest object into the Web client to request information.
Servlet container create a HTTPResponse object.
Servlet container calls HTTPServlet Service object method, HTTPRequest and HTTPResponse go into the Service function.
HTTPServlet call the relevant method in the request for information HTTPRequest.
HTTPServlet call the relevant methods to generate HTTPResponse.
Servlet returns the results to the corresponding Web client.
4, Servlet works:
The client sends a request and Servlet container creates based on the request of ServletRequest and ServletResponse, then call the Servlet Service method to obtain the requested information, processes it, and returns a response.
The method in which the Service Selection and do request method corresponding features, such as doGet, doPost methods. In the Servlet and GenericServlet these methods is no need to define themselves. Although these methods HTTPServlet, but returned Error message, we need to reload themselves.
Servlet and GenericServlet is not based on any agreement, and HTTPServlet is based on HTTP protocol. |
|
|
|