[ Team LiB ] Previous Section Next Section

Hour 5. JSP and Servlet Lifecycles

What You'll Learn in This Hour:

  • How servlets are created, used, and destroyed

  • How JSPs are created, used, and destroyed

  • How containers manage "live" changes to JSPs, servlets, and other classes

  • How to use the servlet application events facilities

Now that you understand the major features of JSPs and servlets, it's time to drill down into some of the underlying structure. So far, you have learned how to use JSPs and servlets to service requests or create responses as part of an application.

Unlike ordinary Java objects, where you control when an object is created and destroyed, JSPs and servlets are created and managed by containers that interact with a Web server. When the Web server determines that a request is destined for a Web component such as a JSP or servlet, it passes control to the container, which then causes the appropriate component to take care of the request. The container is responsible for instantiating, using, and destroying objects. Leaving these functions to the container relieves you from considerable overhead. The container can create and use or reuse as many objects as required to service the workload, resulting in enhanced scalability—and you don't have to worry about anything other than writing the next great application.

It is important to understand the JSP and servlet lifecycle: when and how servlets and JSPs are loaded, executed, and unloaded. Because JSPs are also servlets, it makes sense to start with servlets.

    [ Team LiB ] Previous Section Next Section