Life Cycle of JSPs

JSPs are essentially compiled to servlets and hence follow the life cycle of servlets.

As you can see in Figure 5.2, there are three stages in the life cycle of a JSP, which are similar to the servlet life-cycle stages:

  • Initialization A compiled servlet is initialized by the WebLogic Server when it is loaded for the first time. The compiled servlet of a JSP is initialized by the WebLogic Server every time the JSP is modified.

  • Manage request and response Any requests received by the Web server are forwarded to the compiled servlet to handle. The compiled servlet contains a service() method that is invoked by the WebLogic Server on every browser request. The service() method contains all the Java statements that are embedded in the JSP. The HTML code of the JSP is also contained in the service() method, but as out.println() statements. The service() method contains a request object and a response object as parameters. These are used by the compiled JSP servlet to process the request and send the response. The JSP engine within the WebLogic Server packages the request data in the request object and uses the response object to send the response to the browser. The service() method is used throughout the life cycle of this compiled servlet of the JSP.

  • Termination At the end of the life cycle of the servlet, the server shuts down the servlet and frees up resources. This occurs when the destroy() method of the servlet is called during shutdown of the application server.

Figure 5.2. Life cycle of a JSP.

graphics/05fig02.gif



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net