iTP Secure WebServer System Administrator's Guide (iTPWebSvr 6.0+)

Using NonStop Servlets for JavaServer Pages
(NSJSP)
iTP Secure WebServer System Administrator’s Guide523346-002
9-37
Model-View-Controller Designs
There are two main advantages to this design. 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, and 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.
There are three programming steps 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. The
getServletContext() method is invoked on the ServletConfig object
passed in to a servlet’s init() method and is typically stored as a field in the
servlet class.
2. Obtain a reference to the request dispatcher object for the servlet in use. Use the
getRequestDispatcher(String name) method which takes in the path and
name of the servlet and returns the request dispatcher object.
Figure 9-5. 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