Model 2 (see graphic) is an enhancement to the Model 1 architecture that is designed to address some of these shortcomings. Model 2 is the server-side implementation of the MVC pattern we discussed earlier. Here there is a separation between the components responsible for presentation (JSPs) and the components responsible for processing HTTP requests (controlling servlets). Servlets, acting as controllers, are responsible for creating any beans or other server-side resources that may be used by the presentation components. The servlets also decide (based upon user input extracted from the HTTP request), which presentation component gets the request. This lets the servlets act as a single entry point for the application, making the management of application state, security, and presentation more straightforward.
[click for larger image] Model 2 is the server-side implementation of MVC. The Controller servlet is responsible for handling client HTTP requests. Upon receiving a request, it allocates any server-side resources the view component may require (e.g., EJBs), and passes control to the appropriate JSP (view). The view obtains any information it needs to fulfill the request, and returns formatted HTML to the client. |
In the Model 2 pattern, there is no processing logic within the presentation components (JSPs) themselves. Instead, the JSPs simply perform "classic" view functionality by extracting dynamic information from whatever server-side resources are necessary (e.g., EJBs). JSPs then insert that dynamic content into the static templates defined by the JSP, and pass along the response to the user. By eliminating unnecessary processing logic from JSPs, this technique makes JSP creation and management easier for graphic design teams.
Model 2 Frameworks
A number of frameworks are available to help developers architect MVC-compliant interfaces for their Web applications. Perhaps the best known is Struts (jakarta.apache.org/struts/), an open source project that is part of the Apache Jakarta initiative. The Struts package provides a unified set of reusable components for building user interfaces that can easily be adapted for any Web-based connection (e.g., HTTP requests, WAP, or even standard socket-level applications). Struts ships with a controller servlet, custom JSP tag libraries, and some utility classes.
Struts has a relatively steep learning curve, but most programmers find it worth the effort. If, however, you're looking for something a little easier to manage so that you can get up and running a bit faster, Maverick might be the way to go. Maverick offers many of the same features as Struts, as well as some unique XSLT transformation features.
Different software architectures are applicable in different contexts and use cases. If you're rapidly prototyping a proof of a concept, chances are that a simple Model 1 pattern will be sufficient for your requirements. If, on the other hand, you are developing an application that you intend to roll into production and maintain for years, you should design with flexibility, extensibility, and modularity in mind. Software patterns like MVC and Model 2 provide a powerful design technique that will help ensure that your code remains in use for years to come.
Paul Sholtz is the chief technology officer of PrivacyRight, where he pioneered
the development of service-based access control models for distributed computing
environments. He is currently involved in a number of risk consultation and
security projects for clients in the health care industry and holds a CISSP
certification.