3. Servlet Life Cycle
web.xml file
To learn how to configure the example, refer to the deployment descriptor (the web.xml file), which includes the following configurations:
- A display-name element that spectifies the name that tools use to identify the application.
- A set of filter elements that identify servlet filters contained in the application.
- A set of filter-mapping elements that identify which servlets will have their requests or responses filtered by the filters identifyed by the filter elements. A filter-mapping element can define more than one servlet mapping and more than one URL pattern for a particular filter.
- A set of servlet elements that identify all the servlet instances of the application.
- A set of servlet-mapping elements that map the servlets to URL patterns. More than one URL pattern can be defined for a particular servlet.
- A set of error-page mappings that map exception types to an HTML page, so that the HTML page opens when an exception of that type is thrown by the application.
Servlet Life Cycle
The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps.
-
If an instance of the servlet does not exist, the web container
- Loads the servlet class.
- Creates an instance of the servlet class.
- Initializes the servlet instance by calling the init method. Initialization is covered in Initializing a Servlet
- Invokes the service method, passing request and response objects. Service methods are discussed in Writing Service Method
만약 container가 servlet를 제거하는 것이 필요하면, servlet's destroy method를 호출하여 종료한다.
History
Last edited on 11/13/2008 21:17 by StudioEgo
Comments (0)