Java Reference
In-Depth Information
decisions about the types of components needed, whether servlets, HTML
documents or JavaServer Pages, as well as the processing each component will
do. Careful thought should be given to the responsibilities of each component
of the MVC pattern when designing the application.
The Model-View-Controller (MVC) Pattern
A pattern is a standard approach to solving a particular programming problem.
Recall that the Model-View-Controller (MVC) pattern has three layers:
1. the model, which defines the business rules layer;
2. the view, which defines the user presentation layer; and
3. the controller, which defines the application layer responsible for
managing the application flow.
When developing an application using the MVC pattern, keep each layer as
independent of the others as possible to make later modifications easier. When
using a database, adding a data access layer keeps the application independent
of the particular DBMS being used.
Using the MVC pattern provides more flexibility and maintainability by
creating the user views separate from the controller logic. As its name implies,
the controller component is used to direct, or control, the flow of the applica-
tion, particularly the interaction between views of the data and the database
itself (Figure 12-3). Individual user views may be static Web pages created in
HTML or dynamic Web pages created using JSPs or servlets, depending on
whether dynamic data is displayed on the page.
Initial View
(HTML)
Browser
Parameters and/or
session data
Dynamic HTML
Log out
View 1
(JSP)
Controller
WebStocks class
Session data
Session data
View 2
(HTML)
View 3
(JSP)
Stock Quote Web
Service
Model
StockTrackerDB class
Session data
View n
(JSP or HTML)
StockTracker
Database
FIGURE 12-3
 
Search WWH ::




Custom Search