Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Instant Update


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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.