NonStop Servlets for JSP System Administrator's Guide

Overview and Architecture
NonStop Servlets for JavaServer Pages (NSJSP) System Administrator’s Guide—525644-001
1-8
Model-View-Controller Designs
The second approach is to adopt the model-view-controller design, shown in
Figure 1-4, A Model-View-Controller Design. In this design, processing is divided
between the controller and presentation components. The presentation component, or
View, are JSP pages that generate the HTML or XML response that determines the
user interface rendered by the browser. The controller (a servlet or JSP page) is a
front-end that is not concerned with presentation, just the processing of HTTP
requests. The controller instantiates beans and other objects to be used by the
presentation component.
This design has two main advantages. There is no processing logic in the presentation
component; it simply retrieves objects or beans created by the controller and extracts
the dynamic content for insertion in the JSP static templates. Thus you will have a very
clear separation of presentation and content. Furthermore, as the controller presents a
single point of entry into the application, the management of state and security are
made easier.
These designs are easily implemented using the request dispatcher, which allows one
servlet to utilize the services of another servlet. There are two possible scenarios,
including and forwarding. The response of a servlet can include the output of another
servlet. The included servlet can only send output to the client; it cannot alter the
header information. With forwarding, the original servlet cannot send output to the
client, instead it forwards the request and the response to another servlet.
Three programming steps are involved:
Figure 1-4. A Model-View-Controller Design
JSP
REQ
RES
CLIENT
BROWSER
WEB CONTAINER
1
2
3
4
Data Storage
Java Bean
or Java Servlet
Servlet
3
4
5
Controller
Model
View
VST905.vsd