Implementation of web2.0 MVC pattern based on Dojo Toolkit

Source: Internet
Author: User
Tags json dojo toolkit

Objective

The MVC pattern is the classic pattern in the design pattern, which can effectively separate the data layer, the presentation layer, and the business logic layer. WEB2.0 technology is widely used in the display layer of WEB application because of its good user experience. However, in the traditional web development, the display layer and the business logic layer of the code a large number of coupling, so that the application of the scalability seriously reduced, while the page layer code reusability is also very low. This article introduces how to use Dojo Toolkit to extend the page control of dojo and implement the MVC pattern, effectively separating the code of the presentation layer and the business logic layer, and making the display layer code reusable greatly.

Part One: The difference between the Dojo architecture MVC and the traditional MVC pattern

The traditional MVC pattern

The MVC pattern is the abbreviation for "Model-view-controller", which is translated as "mode-View-controller". The program based on the MVC pattern is generally composed of the three parts of Controller, View and model. Controller primarily accepts user-triggered events (event) in the application, and then Controller updates the Model based on predefined business logic. After model update, model notifies (notify) that the model's view has been registered for the Refresh (refresh) operation, and the final program displays the refreshed view to the user.

Model of the difference:

The traditional MVC pattern model is a javabean, as shown in listing three. In the DOJO architecture of MVC, model is a JSON data structure, encapsulated, the returned data structure in the form of the following:

{“books”:[{“bookName:The art of programming”,”price:90”},
          {“bookName:MVC introduction”,”price:90”}]}

The data flow is different:

In the traditional MVC pattern, the data acquisition process is as follows:

jsp->servlet->service->dao->javabean-> Database

Or

Jsp->servlet-> dao->javabean-> Database

In the web2.0 MVC pattern, the data is transmitted in the following ways:

jsp->javascript->servlet->service->dao->javabean-> Database

Or

Jsp->javascript->servlet-> dao->javabean-> Database

In dojo, for example, when a user sends a data request to a JSP page, it is submitted to the JavaScript function of the Dojo widget, which invokes the corresponding servlet, which converts the data that the servlet takes to JavaScript A JSON data structure that can be identified, and then the widget, based on its own refresh rule, fills the widget's HTML template and displays it to the user.

Differences in the Servlet control layer

It is precisely because of the difference in data flow that led to the traditional MVC control layer and web2.0 control layer is very different, if the traditional MVC control layer is a servlet, then in web2.0, this control role has begun to move from the servlet to Javascrip In T.

In the traditional MVC pattern, the servlet is responsible for data and encapsulation data, and sometimes includes code snippets that refresh the page data, while the JSP is responsible for parsing the data, populating the data, and displaying the data. Given that JSP is also a servlet in the broadest sense, the servlet includes a one-stop service from fetching data, encapsulating data, parsing data, populating data, and displaying data.

In web2.0, the servlet is still responsible for fetching and encapsulating data, but parsing, populating, and displaying data is no longer done by the JSP, and parsing and populating the data is done in JavaScript. The widget that is responsible for parsing and populating data in dojo. So what is Dojo's widget?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.