In Part 1 of this article (JDJ, Vol. 6, issue 2) we discussed the problems associated with J2EE's Servlet/JSP container. In Part 2 we'll discuss Cybelink's Jlink architecture and how it solves those problems.
Jlink Architecture
Jlink is built on various architectural and software design patterns. In this section we'll discuss the software patterns, specifically, the Model-View-Controller (MVC) patterns.
MVC Architectural Pattern
MVC is an architectural pattern that's been widely used in architecting distributed component-based applications. It facilitates the division of the application into logical components that can be designed and developed independently. This division increases the reusability of components by reducing the couplings between them.
In the MVC pattern the Model components represent the business logic (e.g., JavaBeans and EJBs), the View components represent the UI that displays the processing results of the business logic, and the Controller components manage the coordination between the Model and View components. Figure 1 shows the relationship between the various components of the MVC pattern. The Model components maintain the state of the business object and when the state of the Model object changes, they notify the View components, which update the UI with new data. It's also possible for the View components to request state changes directly from the Model components. The View components enable the Controller components to change the display according to the user's request. The Controller components map the user's actions from the View to the Model components.
Mapping MVC with Servlets and JSP
In Part 1 we discussed the problems associated with Sun's Servlet/JSP container; in the previous section we discussed the MVC pattern. Now that we understand the Servlet/JSP Container model and the MVC pattern, we can start applying the MVC to the Servlet/JSP Container model. Tra-
ditionally, the MVC pattern was used to build client/server applications; in this section we'll see how we can use it to develop Web-based applications using Servlets/JSP. In our Jlink we'll use the JSP and JavaBean as the Controller components, the JSP pages as the View components, and JavaBeans as Model components.
JSP and JavaBeans as
Controller Components
The AppController.jsp (see Listing 1) and AppController bean (see Listing 2) are used as Controller components that are responsible for accepting the HTTP requests and passing them to the appropriate RequestHandler object. (Listings 1-7 can be found on the JDJ Web site, www.JavaDevelopersJournal.com.)The RequestHandler objects are designed using JavaBeans. These beans strip the browser requests and send them to the appropriate Command JavaBean components. The Command beans are modeled after Command Design patterns. Before handling the request to the RequestHandler objects, the AppController.jsp creates a ClientContext (see Listing 3) object for each request and passes it to the RequestHandler object. The ClientContext contains javax.servlet
.HttpRequest, javax.servlet.HttpResponse, and javax.servlet.http.HttpSession objects. Thus the ClientContext encapsulates the Client state by maintaining the necessary objects in one place, eliminating the spaghetti code discussed in Part 1. Other objects should get parameters, such as Request and Query, from the ClientContext object.
|