Web Client Life Cycle
The server-side portion of a Web client consists of Web components, static resource files such as images, and helper classes and libraries. 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 these services into account, the process for creating and running a Web client is different from 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 e-mail.
Before it can be executed, a Web client must be packaged into a Web application archive (WAR), which is a JAR similar to the package used for Java class libraries, and installed (or deployed) into a Web container.
Certain aspects of Web client behavior can be configured when it is deployed. The configuration information is maintained in a text file in XML format called a Web application deployment descriptor. When you create Web clients and components using the J2EE SDK
deploytoolutility, it automatically generates or updates the deployment descriptor based on data that you enter in
deploytoolwizards 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 client can be summarized as follows:
- Develop the Web component code (including possibly a deployment descriptor).
- Package the Web client components along with any static resources (for example, images) and helper classes referenced by the component.
- Deploy the application.
- Access a URL that references the Web client.
Developing Web component code is covered in chapters 10 and 11. Steps 2 through 4 are expanded on in the following sections, illustrated with a Hello, World-style application. This application allows a user to enter a name into an HTML form (Figure 9-1)
Figure 9-1 Greeting Form
and then displays a greeting after the name is submitted (Figure 9-2)
Figure 9-2 Response
The Hello application contains two Web components that generate the greeting and the response. This tutorial has two versions of this application: a servlet version called
Hello1Appin which the components are implemented by two servlet classes,
ResponseServlet.java, and a JSP version called
Hello2Appin which the components are implemented by two JSP pages,
response.jsp. The two versions are used to illustrate the tasks involved in packaging, deploying, and running a J2EE application that contains Web components.