Web Development in J2EE Using the MVC Design Pattern
Web services application development is a huge topic covering a broad range of technologies and topics. In this article we will discuss Web services development in J2EE and examine the Model/View/Controller design pattern, thereby explaining how it separates business logic implementation and persistence from presentation. We shall briefly introduce the Struts Framework, one that facilitates web services development within the IBM WebSphere Studio Application Developer edition. (This article was originally published in the June 2004 issue of Plug-In).
Web Development in J2EE Using the MVC Design Pattern - Applying the Model/View/Controller Design Pattern (Page 4 of 5 )
IBM’s WebSphere Application Server has adopted the “Model, View, Controller (MVC)” design pattern created by Xerox PARC for Smalltalk-80 in the 1980s. This model is becoming increasingly popular with the programming community. Significantly, MVC was selected by Sun Microsystems as the recommended model for its J2EE specifications. MVC can be used by any programming language or platform and enforces the separation between (1) the view, (2) the model, and (3) the controller. It separates data input and processing from data output.
The view interface presents us with a wide range of options such as making a selection from a series of radio buttons or a drop down list. For example, the user can select the type of delivery service, i.e. UPS, FedEx, USPS, or DHL from the list. Traditionally, the view is presented in HTML format. However, an interface may be also presented as XHTML or XML/ XSLT templates. Because the view is display-neutral, it can present many diverse views of the same data. A view always reflects any event changes occurring in the “model” layer.
The model contains business objects which interact directly with JavaBeans or Enterprise JavaBeans (EJBs). They implement transactional business rules such as data persistence or retrieval.
The Controller serves as interpreter by intercepting client requests and calling a servlet’s service() function to fulfill the client’s request. The controller applies no formatting nor does it output anything. It serves only as a notification service both to the view and model to respond accordingly.