[ Team LiB ] Previous Section Next Section

Summary

In this hour you learned that servlets and JavaServer Pages have distinct phases that they go through during their existence as part of a Web application. Containers are responsible for loading, instantiating, initializing, using, and destroying Web application components. As part of these activities, the container will invoke lifecycle methods, such as jspInit or jspDestroy, to allow you the opportunity to perform component specific operations.

JSPs must be compiled by a container before they can be used. A JSP container will compile a JSP when necessary. On the other hand, some containers will not update servlets, even if their class files have changed. In any case, classes that are part of the Web application and are not servlets are usually not reloaded. To be certain that all of the components are refreshed, package them in a WAR and redeploy the application rather than replacing individual pieces. Tools like Apache's Ant make this process much easier.

You can also monitor events that occur at the application level by writing a listener and registering it with a container. This is useful for managing resources that are shared by all of the Web application components. Several interfaces for listeners exist that permit you to know when an application is loaded or unloaded, when it begins to process a request, or when sessions are created or destroyed. In addition, you can learn about changes to attributes that are associated with a servlet context, request, or HTTP session.

    [ Team LiB ] Previous Section Next Section