Created: 6.15
A, Servlet's API (life cycle)
(1) Servlet interface method
1)init(ServletConfig config)
When to perform: when the servlet objects created to perform
ServletConfig: represents the servlet configuration object
ServletConfig can get to understand what configuration information :()
web.xml initialization parameters:
2)service(ServletRequest request,ServletResponse response)
When to perform: Each request will be executed
ServletRequest: Representative ServletRequest request that the information inside the package http request
ServletResponse: Representative response information that is to be wrapped responsive
3)destroy()
When to perform: when the servlet destruction of execution
* Note: When testing init and destroy methods, need to restart the server for testing (open to close the whole process test server)
Code:
* Does not require new objects, Tomcat help create the object and call its methods
In the browser test:
Request several times, service method execution times
Shut down the server
(2) Servlet life cycle (interview questions)
1) Servlet when to create
By default the object is created the first time you access the servlet
2) Servlet when destroyed
Close servlet server is destroyed
3) The method of execution is bound per visit
service(ServletRequest req, ServletResponse res)方法