InfoCenter Home > 4.2.1.1: Servlet lifecycle
Instantiation and initializationThe Web container (the Application Server entity that processes servlets, JSP files, and other types of server-side include coding) creates an instance of the servlet. The Web container creates the servlet configuration object and uses it to pass the servlet initialization parameters to the init method. The servlet configuration object persists until the servlet is destroyed and are applied to all invocations of that servlet until the servlet is destroyed. If the initialization is successful, the servlet is available for service. If the initialization fails, the Web container unloads the servlet. The administrator can set an application and its servlets to be unavailable for service. In such cases, the application and servlets remain unavailable until the administrator changes them to available. Servicing requestsA client request arrives at the Application Server. The Web container creates a request object and a response object. The Web container invokes the servlet service method, passing the request and response objects. The service method gets information about the request from the request object, processes the request, and uses methods of the response object to create the client response. The service method can invoke other methods to process the request, such as doGet(), doPost(), or methods you write. TerminationThe Web container invokes the servlet's destroy() method when appropriate and unloads the servlet. The Java Virtual Machine performs garbage collection after the destroy. More on the initialization and termination phasesA Web container creates an instance of a servlet at the following times:
The init method executes only one time during the lifetime of the servlet. It executes when the Web container loads the servlet. The init method is not repeated regardless of how many clients access the servlet. The destroy() method executes only one time during the lifetime of the servlet. That happens when the Web container stops the servlet. Typically, servlets are stopped as part of the process of stopping the application.
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|