[ Team LiB ] Previous Section Next Section

20.8 The MVC Paradigm for Web Applications

MVC is an acronym for Model-View-Controller, a powerful object-oriented architecture used for graphical user interfaces and also adopted for web applications. The Model is the object or objects upon which that application acts: they are the data. The objects that make up the Model are the core classes of the application. The View is the object or objects that display the model to the user. The Controller is the object that ties everything together, creating view objects for the model and translating the user's interactions with the view into modifications of the model.

In a Java web application, the Controller is a special-purpose servlet and the View, or Views, are JSP pages. The Controller servlet handles all incoming requests, examines them, takes any necessary actions on the Model, and then dispatches the request to an appropriate JSP page, which displays a response to the user. The Model for a web application can be any kind of object, although, by convention, Model objects follow JavaBeans naming conventions with get/set property accessor methods.

The examples that follow constitute a simple web application, named ListManager, for managing a mailing list. As pictured in Figure 20-2, this web application allows users to subscribe to, set delivery preferences for, or unsubscribe from a mailing list. (The example program is not capable of actually sending email to the list subscribers, however.) In the following sections we'll see the Model classes, the Controller servlet, and the JSP views for this web application. Because the Model, Controller, and Views are interdependent, you may need to read through these examples twice in order to understand all the details.

Figure 20-2. The ListManager web application
figs/Jex3_2002.gif
    [ Team LiB ] Previous Section Next Section