The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Web Component Life Cycle

The J2EE platform provides many supporting services that enhance the capabilities of web components and make them easier to develop. However, because it must take into account these services, the process for creating and running a web component is different than that of traditional stand-alone Java classes.

Web components run within an environment called a web container. The web container provides services such as request dispatching, security, concurrency, and life cycle management. It also gives web components access to the J2EE platform APIs such as naming, transactions, and email. Before it can be executed, a web component must be installed (or deployed) into a web container.

Certain aspects of web component behavior can be configured when it is packaged and deployed. The configuration information is maintained in a text file in XML format called a web application deployment descriptor. When you package and deploy web components using the J2EE SDK deploytool, it automatically generates or updates the deployment descriptor based on data that you enter in deploytool wizards and inspectors. You can also manually create a deployment descriptor according to the schema described in the Java Servlet specification.

The process for creating, deploying, and executing a web component can be summarized as follows:

  1. Develop the web component code (including possibly a deployment descriptor).
  2. Package the web component along with any static resources (for example, images) referenced by the component.
  3. Deploy the J2EE application.
  4. Access a URL that references the web component.

These steps are expanded on in the following sections and are illustrated with the hello application. This application allows a user to enter a name into an HTML form:

and then displays a greeting after the name is submitted:

The hello application contains two web components: greeting and response. This tutorial has two versions of this application: a servlet version called hello1 in which the web components are implemented by two servlet classes, GreetingServlet.java and ResponseServlet.java and a JSP version called hello2 in which the web components are implemented by two JSP pages, greeting.jsp and response.jsp. The two versions are used to illustrate the tasks involved in packaging and deploying a J2EE application that contains web components.

Home
TOC
PREV TOC NEXT Search
Feedback