C H A P T E R 2 |
Getting Started |
This chapter outlines the mechanics of using the Web Application Framework tools to build a J2EE web application.
This chapter contains the following topics:
This document introduces developers to the mechanics and techniques used to build Web applications with the Web Application Framework tools.
It is intended for developers who are at least somewhat familiar with building web applications using existing J2EE web technologies (servlets and JSP pages), but new to building web applications using the Web Application Framework.
This document assumes Java expertise and familiarity with the development and deployment procedures for the specific servlet container and development tools being used.
Because the Web Application Framework is foremost a design pattern and a set of interfaces, the examples in this document show only the most basic way of creating a Web Application Framework application, by extending existing Web Application Framework implementation base classes and manually constructing certain application objects. This is only one possible way to create a Web Application Framework application.
There are two reasons for not showing more advanced techniques in this document. First, starting at a fundamental level is the most direct way to impart how the Web Application Framework works to someone new to the framework. Being able to see exactly how the framework interacts with the application is critical to getting the most out of the Web Application Framework.
Second, building an application using these fundamental techniques is a prerequisite to fully understanding the many possible ways to build Web Application Framework applications. Features that extend the Web Application Framework to add additional capabilities are built on the techniques demonstrated in this document. After understanding these basic examples, you have a greater understanding of how these features extend and complement the Web Application Framework core, and you are able to optionally decide not to use them and instead construct your own Web Application Framework extensions (or simply fall back to a more basic approach where necessary).
The ultimate goal of this document then is to introduce developers to the most fundamental way to build Web Application Framework applications, so they become familiar with Web Application Framework's interactions with applications built on top of the framework, and more fluent in the Web Application Framework itself.
Writing a Web Application Framework application consists of first laying out an application structure, and incrementally adding Web Application Framework objects to that structure. Although this can be done entirely by hand and from scratch, the task has been simplified by creating the Web Application Framework tools module for the Sun Java Studio Enterprise 7 that assists developers in writing their Web Application Framework applications. With the assistance of these tools, creating a Web Application Framework application becomes a simple process of generating Web Application Framework components using wizards, and customizing them to an application.
Before demonstrating the creation of a simple Web Application Framework application, you will cover the basics of how a Web Application Framework application is structured.
There are terms in this document such as application, module, and components. These terms can be confusing, because they are also used in more general Web architecture and development discussions.
The following table contains a list of the most important terms found in this tutorial.
* Refer to the Java 2 Platform Enterprise Edition Specification v1.2 (J2EE) section J2EE8.1 for a detailed explanation of this term.
The Web Application Framework provides formal application and module entities. A Web Application Framework application is a base Java package that contains one or more sub-packages (Web Application Framework modules). It is perfectly acceptable for an application to consist of only one module, and it is likely be the common situation for smaller applications. Each module inherits behavior from its parent application-level components, and might also customize this behavior separately from other modules.
In J2EE web application container terms, a Web Application Framework application corresponds one-to-one with a servlet context, and thus is subject to the constraints enforced by the container for servlet contexts.
Before starting to develop your application, you should first decide how it should be organized:
Avoid over-categorizing your application into several modules simply because the Web Application Framework provides this capability. In many cases, one module is sufficient.
The application package name can be arbitrarily complex and will likely reflect your organization's packaging strategy. Each of your modules becomes a package beneath this application package.
In Apache Tomcat, the directory immediately beneath the /webapps directory would bear this name. In the Sun Java System Application Server, the directory immediately beneath the $instance_dir/applications/j2ee-modules directory would bear this name. The deployed application name is the same as the name WAR file name.
For example, if you have two Application Framework modules (named module1 and module2) that comprise a Web Application Framework application, you would call this application myapp. The full application package name would be com.mycompany.myapp.
In general, the application package name should be different from that of any of its modules.
For example, your first instinct might be to name both your application and its primary module foo. This can easily lead to confusion for someone trying to understand your application and your application development tools. Instead, consider naming the application package something like fooapp, or calling the primary module something like main or module1. This makes your application structure much easier to understand, especially when you add to it in the future.
You will now develop a simple application so you can experience using the Web Application Framework and its tools. This application consists of two pages: a login page, and a customer account page, and demonstrates the following:
This tutorial is divided into sections and tasks the steps required to develop the application. Each section addresses a broad topic, at the end of which you have an application that you can run.
Each task within a chapter is a relatively self-contained topic and contains several more detailed steps.
Copyright © 2004, Sun Microsystems, Inc. All Rights Reserved.