The MVC Pattern in the Rental Web Application


The rental Web application's design uses the Model-View-Controller (MVC) design pattern as shown in Figure 10-7. The Web server and servlet container respond to requests that come from the user's Web browser. The requests are either for static content or dynamic content. Those requests that require a dynamic response are directed to the controller, which in this example is the ReservationServlet. The controller accesses the ReservationService to obtain the required persistent objects. These objects are stored in the ReservationModel. The ReservationModel is a container that holds the persistent objects and provides convenience features for the view. JavaServer Pages (JSPs) provide various views of the model. Each JSP generates HTML using the contents of the ReservationModel.

click to expand
Figure 10-7: The MVC pattern in the rental Web application

In the designs examined in this chapter, the view works with live, that is to say managed, application data objects. Although this is not strictly required, this approach provides maximum flexibility to the developers of the view, since JDO will transparently navigate the persistent object model to find any persistent information desired. After the JSP has generated the HTML, execution returns to the controller servlet, which can then decide what to do with the model.

As discussed in Chapter 9, when using live application data objects, JDO exceptions that reflect operational conditions can be thrown at any time, since they are unchecked exceptions. To handle the possible error conditions, every JSP that generates a view using persistent objects should reference an exception handling page in the JSP page directive. In the exception handling page, the exception can then be handled as desired. Something will have to be displayed to the user, and any logging that needs to occur can be done.

Although Figure 10-7 shows the general idea of the Web application that uses JDO, there are some important design issues that arise from the managed nature of persistent objects. The Web application designer must decide how the service that uses JDO relates to the request. Is it a new service for each request or a service that is shared among many requests? If shared, is it shared only among the requests coming from one user or among requests coming from many users? Depending on how the service is used, various management strategies are required for the application data objects.




Using and Understanding Java Data Objects
Using and Understanding Java Data Objects
ISBN: 1590590430
EAN: 2147483647
Year: 2005
Pages: 156
Authors: David Ezzio

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net