Objects in the presentation layer produce the pages or screens that users physically see and use. There are several aspects to the presentation side: static content, dynamic content, and navigation. For J2EE applications, HTML pages typically provide static content, and a combination of JSPs and servlets usually provide dynamic content. For applications that require special effects (e.g., mouse-overs), Javascript can be used in combination with either static or dynamically produced HTML. Users navigate pages using controls (e.g., push buttons) on the page. Figure 15.1 depicts the role of the presentation layer.
Although it is technically possible to embed all presentation logic within JSPs, this type of architecture is difficult to maintain. A better method is to organize the presentation tier in a way that separates page display, user input validation, data processing, navigation, and security. This type of organization is often referred to as a model-view-controller (MVC) architecture. Although an MVC architecture results in more components to maintain, they are all relatively simple. For a more detailed discussion of the MVC pattern, see the Java Web site (http://java.sun.com/blueprints/patterns/MVC.html).
The most common framework used to organize the presentation layer (and support an MVC architecture) is Struts, the open source package from Apache introduced in chapter 5 and available from http://jakarta.apache.org/struts/. As with many other frameworks, some of Struts' features are commonly used and others are rarely used in practice. I'll concentrate on the package's most commonly used features here to give you a basic understanding of how to use it to implement the presentation layer. Spielman (2003) is a good source for more in-depth information on Struts.
Some developers use XSL transformations to produce dynamic content, but the technique is not a formal part of the J2EE specification and produces mixed success. Although you might consider this option if your data exists in XML format, formatting data with XML merely to run transformations on it to produce HTML usually results in high development and maintenance costs.
Other types of presentation components are applets and Swing. These technologies are not J2EE specific and thus are out of the scope of this book. However, with a layered architecture, you certainly can deploy applets or Swing clients.
In a layered architecture, the presentation layer is not self-contained. Presentation objects rely on client stubs and the value objects used with those stubs in the deployment layer for dynamic content. You can change aspects of any other layer without having to change the presentation layer. Likewise, you can make changes in presentation without affecting the other software layers.