NonStop Servlets for JavaServer Pages (5.0) System Administrator's Guide
Overview and Architecture
NonStop Servlets for JavaServer Pages (NSJSP) System Administrator’s Guide—525644-002
1-9
Model-View-Controller Designs
The second approach is to adopt the 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, consists of 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 Java Beans and other objects to be used by the presentation component.
The MVC design has two advantages. First, no processing logic exists in the
presentation component; it simply retrieves objects or Java Beans created by the
controller and extracts the dynamic content for insertion in the JSP static templates.
Creating clear separation of presentation and content the controller presents a single
point of entry into the application, the management of state and security is easy.
The MVC design is easily implemented using the request dispatcher, which allows one
servlet to use the services of another servlet by including or by forwarding. For
including, 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. For
forwarding, the original servlet cannot send output to the client, instead the servlet
forwards the request and the response to another servlet.
Three programming steps are involved:
1. Obtain a reference to the servlet context by invoking getServletContext().
The return value is a javax.servlet.ServletContext object, which contains
several methods for the servlet to communicate with the container.
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