Java Web Programming with Eclipse contents
Last modified February 25, 2009 07:42 pm
In this chapter, we continue building the publisher application with the data access object pattern described in the previous chapter on data access objects and the model-view-controller pattern described in the chapter on JSP.
A domain model is an object model of the domain that incorporates both behavior and data. In our case, the domain model consists of a single entity called NewsItem, which represents a news item to be published by RSS. For the purpose of this lab, we have reduced the number of attributes of a news item to a minimum. The following screen shot shows the data model used in this chapter.
The following screen shot shows the various concerns within our application organized into a layered architecture. This architecture will form a basis for future iterations of the system in which we add functionality.
Actually, the architecture is not purely layered in the sense that elements of the presentation layer access elements of the persistence layer. In a strictly layered architecture, elements of the presentation layer would only be permitted to access elements of the business logic layer.
In the outermost layer, there is the user's web browser that makes TCP connections to the tomcat web container (also called a servlet/JSP container), through which it sends HTTP request messages.
The second layer is Tomcat, which parses incoming HTTP request messages into instances of the HttpSerlvetRequest class, and then passes these objects to the doGet or doPost methods of an appropriate servlet based on the request URL.
The third layer is the presentation layer, which is comprised of servlets and JSP scripts. The servlets act as controllers (request handlers) because their service methods (doGet, doPost) act as entry points into the web application. In response to user input, the servlets may lookup one or more business objects through the persistence layer and may invoke requested business functionality on them. After business functions have completed, the servlets invoke JSP scripts, passing to them references to appropriate domain objects. The purpose of the JSP is to generate the HTML to display to the user an appropriate view of the application state.
Some authors talk about a model-view-controller architecture in which servlets comprise the controller, JSP the view, and business logic the model.
The domain objects are plain old Java objects (POJOs) that model the data and behaviors of the (business) problem being solved. In our simple application, the business logic layer is comprised of instances of a class called NewsItem.
The persistence service is comprised of data access objects (DAOs). Recall that these classes are responsible for providing services needed to persist the application state as embodied in the domain objects. For each persistent domain object, there is a DAO; thus for our application, we have a single class called NewsItemDAO.
Finally, the database is situated on the lowest layer of the application. Reads and writes into the database will be performed by the methods in the DAOs. The following screen shot provides another illustration of the basic architecture that will be followed in this chapter.