Model 2 Versus Model 1 Architecture

About the Model 2 Versus Model 1 Architecture

Early web application design regarded the JSP page as the focal point for the entire application. Termed Model 1 architecture, the JSP page not only contains the display elements to output HTML, but is also responsible for extracting HTTP request parameters, call the business logic (implemented in JavaBeans, if not directly in the JSP), and handle the HTTP session. Although Model 1 is suitable for simple applications, this architecture usually leads to a significant amount of scriptlets (Java code embedded within HTML code in the JSP page), especially if there is a significant amount of request processing to be performed.

The following diagram illustrates the JSP Model 1 architecture.

JSP Model 1 architecture

As a response to the Model 1 architecture, Apache Software Organization developed the Jakarta Project's Struts framework. Struts is an open source framework for building web applications that integrate with standard technologies, such as Java Servlets, JavaBeans, and JSP. Struts offers many benefits to the web application developer, including Model 2 implementation of Model-View-Controller (MVC) design patterns in JSP web applications. The MVC Model 2 paradigm applied to web applications lets you separate display code (for example, HTML and tag libraries) from flow control logic (Struts action classes).

The following figure illustrates the Model 2 web application architecture, where Servlets control the flow of the web application and delegate the business logic to external components, usually JavaBeans or EJBs, while JSP pages generate the HTML for web browsers:

JSP Model 2 architecture

The following information gives a brief overview of the MVC Model 2 design pattern and the role of Oracle ADF:

  • The Model portion of an MVC-based system typically comprises JavaBean classes that define the internal state of the system; they also specify the actions that can be taken to change that state.

    When you create your web application using the Oracle Application Development Framework (Oracle ADF), binding to the model layer is handled for you. Otherwise, you will need to create the data binding implementation for the view layer. For additional information about Oracle ADF, see About the J2EE Platform and Oracle ADF.

  • The View portion is constructed using JSP technology or Oracle ADF UIX technology. JSP pages can contain static HTML (or XML) text called "template text", plus the ability to insert dynamic content based on the interpretation (at page request time) of special action tags. The JSP environment includes a set of custom JSP tag libraries (such as the Struts tag libraries), standard JSP action tags (such as those described in the JavaServer Pages Specification), and a facility to install your own JSP custom tag libraries.

    When you use the Oracle Application Development Framework (Oracle ADF), you can take advantage of the data binding facilities in JDeveloper that allow your web pages to display databound dynamic content from the model layer. For complete information about the data controls in JDeveloper, see About Oracle ADF Data Controls.

  • The Controller portion of the application is focused on receiving requests from the client (typically a user running a web browser), deciding what business logic function is to be performed, and then delegating responsibility for producing the next phase of the user interface to an appropriate View component. In Struts, the primary components of the Controller is a servlet of class ActionServlet and the class RequestProcessor.

    When you use the Struts Page Flow Diagram in JDeveloper, you can work with a visual representation of the application logic. For additional information about the design time for Struts, see About Struts Support in JDeveloper.

posted on 2004-10-26 13:36  Java & .Net  阅读(363)  评论(0编辑  收藏  举报

导航