ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/program/servlife.htm

50 lines
2.7 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Servlet lifecycle</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h4><A NAME="servlife"></A>Servlet lifecycle</h4>
<p>The lifecycle of a servlet begins when it is loaded into Application Server memory and ends when the servlet is terminated or reloaded. </p>
<img src="rzaiz521.gif" width="280" height="454" alt="Servlet lifecycle" align="right">
<p><strong>Instantiation and initialization</strong></p>
<p>The servlet engine (the WebSphere Application Server - Express function that processes servlets and JSP files) creates an instance of the servlet. The servlet engine creates the servlet configuration object and uses it to pass the servlet initialization parameters to the init() method. The initialization parameters persist until the servlet is destroyed and are applied to all invocations of that servlet.</p>
<p>If the initialization is successful, the servlet is available for service. If the initialization fails, the servlet engine unloads the servlet. The WebSphere Application Server - Express administrator can set a Web application and its servlets to be unavailable for service. In such cases, the Web application and servlet remain unavailable until the administrator changes them to be available.</p>
<p><strong>Servicing requests</strong></p>
<p>WebSphere Application Server - Express receives a client request. The servlet engine creates a request object and a response object. The servlet engine invokes the servlet service() method, passing the request and response objects.</p>
<p>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.</p>
<p><strong>Termination</strong></p>
<p>The servlet engine stops a servlet by invoking the servlet's destroy() method. Typically, a servlet's destroy() method is invoked when the servlet engine is stopping a Web application which contains the servlet. The destroy() method runs only one time during the lifetime of the servlet and signals the end of the servlet.</p>
<p>After a servlet's destroy() method is invoked, the servlet engine unloads the servlet, and the Java virtual machine eventually performs garbage collection on the memory resources associated with the servlet.</p>
</body>
</html>