[ Team LiB ] Previous Section Next Section


The Workshop is designed to help you review what you have learned and help you to further increase your understanding of the material covered in this chapter.



What is the purpose of the ServletConfig object?


When is a servlet or JSP destroyed?


Which interface in the application event facilities is best used to initialize resources that are used for the duration of a request?



A ServletConfig object provides access to JSP or servlet specific initialization parameters and to a servlet context. It can also give you the name of the servlet or JSP as defined in the deployment descriptor.


A servlet or JSP is only destroyed when the application or container is shut down, or when the container decides to unload the JSP or servlet for some reason. (It may do this for performance.) They are not destroyed at the end of processing a request; remember that Web components are often reused.


An object that implements ServletRequestListener is appropriate. This interface will let you know when servicing a request begins and when the request is about to be destroyed.


  1. Write a JSP that reads several initialization parameters and outputs them to a Web page.

  2. Run the listener example and reload the browser page so that the JSP is invoked more than once. Note which events occur each time the JSP is invoked.

  3. Extend the example to use a ServletRequestListener so that you can see when requests begin to be processed.

    [ Team LiB ] Previous Section Next Section