| CONTENTS | PREV | NEXT | INDEX | Designing Enterprise Applications with the J2EETM Platform, Second Edition |
The Web tier of the J2EE platform makes J2EE applications available on the World Wide Web. JSP pages and servlets are Web components that supersede legacy technologies by providing portable high-level system services. These services include transactions, data access, state maintenance, security, and distribution. Using custom tags and standard tag libraries in JSP pages improves code quality and eases maintenance.
The Model-View-Controller (MVC) architectural design pattern is recommended for most interactive Web applications. MVC makes application functionality more reusable, and simplifies adding and modifying client types, data views, and workflow.
A Model 1 application is a set of JSP pages that are statically linked to one another. A Model 2 application has a centralized controller that dynamically performs request dispatching and view selection. Model 2 is the preferred architecture for Web applications, because it provides more flexibility and is more maintainable than a Model 1 design.
A Web-tier application framework is a domain-neutral layer of services, usually based on MVC, that simplifies constructing an interactive Web application. Such a framework can reduce an application's time-to-market, improve code quality, and ease maintenance. It's usually preferable to choose an existing framework rather than to build one.
The simplest framework design has a single controller that receives requests from browsers, dispatches calls to an application model, and displays results. Multiple controllers can support multiple types of Web-tier clients by communicating with them in their native protocols. A protocol router provides a single point of control for application-wide services such as security and logging.
A Web-tier templating mechanism can improve page layout consistency. The templating mechanism uses a template file to assemble individual views into a single composite view. A template file specifies layout for a set of composite views. Templating makes an application more flexible and makes content more reusable.
Servlets are useful for implementing application services, generating binary content, and controlling applications. JSP pages are best for creating textual content with embedded references to external data. Servlet filters can extend the functionality of an existing servlet, JSP page, or servlet filter.
Web application state resides in either application scope, session scope, request scope, or page scope. State in session scope has the greatest impact on scalability, because its size is proportional to the number of users. Using a stateful session bean is the recommended way to maintain session-scope state. Web-only applications should store session-scope state in HTTP session attributes.
Some J2EE products allow a Web application to be distributed for improved scalability and availability. How a platform implementation manages load in a distributed application is vendor-specific. JSP pages, custom tags, and servlets in a distributed Web application must follow additional programming restrictions.