Java Reference
In-Depth Information
In this project, the controller component is a servlet. Analogous to an air
traffic controller or police officer directing traffic, the controller servlet is
responsible for directing requests for the next Web page view from the user,
except in those few cases when a Web page invokes another Web page directly.
In all cases where data must be obtained from the database, the request flows
through the controller servlet. Only the controller servlet contains logic for
accessing the database; database access is handled entirely through the data
access class, StockTrackerDB, which models the database for the application.
Additionally, the servlet obtains stock quote data from the Web service and then
provides the data to the requesting view. Obviously, all requests and responses
between the browser and the Web pages (whether HTML or JSP) and servlet
communicate through the Web server, which is not included in Figure 12-3 for
the sake of simplicity.
Model-View-Controller Pattern
A pattern is a standard approach to solving a particular
programming problem. The Model-View-Controller pattern
has three layers: the model, which defines the business rules
layer; the view, which defines the user presentation layer; and
the controller, which defines the application layer responsible for
managing the application flow. 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.
Understanding Web Application Processing
Understanding the interaction between the servlet, JavaServer Pages, and HTML
documents is important for deciding how to structure a Web application. It also
is necessary to understand how data is incorporated into dynamic Web pages,
which makes a Web application possible. Static Web pages can have some limited
user interaction through client-side processing of data; however, dynamic Web
pages require server-side processing.
Client-side refers to processing that uses resources available only on the
client. An example of a client-side process is verification that an input field is
not empty. Server-side refers to processing that uses resources on the server, as
in verifying that the value of a user ID input field exists in a database. Server-side
processing requires communication between the client (browser) and the Web
server. Web applications often use a combination of client-side and server-side
processing.
Static Web Pages
A Web browser interacts with a Web server using the same set of rules
whether the Web page is static or dynamic. Web browsers and Web servers com-
municate with each other using Hypertext Transfer Protocol , or HTTP , which
is a standard set of rules, or protocol, used for communication over the Internet.
A request for a Web page from the browser to the Web server is known as an
Search WWH ::




Custom Search