CN101587435A - Method for realizing MVC - Google Patents

Method for realizing MVC Download PDF

Info

Publication number
CN101587435A
CN101587435A CNA200810111953XA CN200810111953A CN101587435A CN 101587435 A CN101587435 A CN 101587435A CN A200810111953X A CNA200810111953X A CN A200810111953XA CN 200810111953 A CN200810111953 A CN 200810111953A CN 101587435 A CN101587435 A CN 101587435A
Authority
CN
China
Prior art keywords
controller
javascript
model
user
page
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CNA200810111953XA
Other languages
Chinese (zh)
Inventor
黄平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yiqitong It Tech Co Ltd Beijing
Original Assignee
Yiqitong It Tech Co Ltd Beijing
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yiqitong It Tech Co Ltd Beijing filed Critical Yiqitong It Tech Co Ltd Beijing
Priority to CNA200810111953XA priority Critical patent/CN101587435A/en
Publication of CN101587435A publication Critical patent/CN101587435A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention provides a method used for realizing MVC by taking JavaScript as a controller. Models and view-interaction with a user are realized by HTML under JavaScript MVC. Models-realization of service logic in a system and generation of HTML code snippets are realized by JSP. The models mainly provide part of code snippets for the view but do not take charge of the arrangement of entire page display and the control of page switching. The controller, which is realized through JavaScript, is a bridge between the models and the view and determines which models are shown on the page. Through JavaScript MVC, the method ensures convenient operation of developers and increases the development efficiency to develop program quickly. Moreover, because JavaScript MVC is based on Ajax, local page refreshing is realized and friendlier interfaces can be provided for users to ensure excellent user experience.

Description

A kind of method that realizes MVC
Technical field:
The present invention relates to the Application development environ-ment of Web platform, particularly relate to the method for a kind of MVC of realization.
Background technology
Along with the continuous development of network technology, the trend of setting up of current information system is to adopt the B/S structure, user interface realizes by the WWW browser, few part things logic realizes at front end, but mainly the things logic realizes at server end, forms so-called three-decker MVC.
Current J2EE exploitation mainly is to adopt MVC pattern (Model-View-Controller, model-view-director mode).It is divided into three essential parts to software systems: model (Model), view (View) and controller (Controller).The purpose of MVC pattern is exactly to realize the function division of labor of Web system:
View-be used for is mutual with the user's, realizes with JSP usually.
Service logic in model-realization system can realize with JavaBean or EJB usually.
Controller-be the bridge of linking up between model and the view, the request that it can assign users also selects appropriate view to show being used for.Controller is realized by servlet.
The problem that this pattern exists is:
Switching between the User is that the page refreshes entirely, and user availability is bad.
Because controller is to adopt servlet to realize, therefore, often will restart server in the time of modification.
Can not be suitable fully based on the existing framework of the application of enterprise, so the necessary unitized overall development platform of intra-company, the company's market competitive power improved.
Summary of the invention:
The present invention provides the method for a kind of MVC of realization for addressing the above problem weak point,
Realize the MVC model based on javascript as controller,
View-be used for is mutual with the user's, realizes with HTML;
Service logic in model-realization system, and generate the HTML code fragment, realize by JSP;
Controller-be the bridge of linking up between model and the view, it determines those models to show to the page.
Described model-be mainly view the partial code fragment is provided, but the control of switching between the layout that not responsible full page shows and the page.
Described controller is realized by javascript.
The first step, the user carries out concrete operations on the page, javascript of WEB server calls,
In second step,, directly call the code snippet that background java realizes obtaining html by AJAX;
In the 3rd step, after background java is finished,, carry out a javascript and realize that the html code snippet that produces is set on the corresponding DOM by the AJAX call back function.The described first step specifically comprises
A1. create a controller object controller earlier;
A2. assemble data object;
A3., the call back function of controller is set
A4., controller is set, model url, domID.
In described second step, specifically comprise
B1. judge whether the user logins;
B2. carry out service logic;
B3. execution model url obtains the code snippet of some html.
In described the 3rd step, specifically comprise
C1. it is unusual to judge whether the background program execution has, if having, then points out concrete error message; If not unusual, carry out next step C2;
C2. judge whether the user is overtime,, then eject login frame, please the user login again,, carry out next step C3 if do not have overtimely if overtime;
C3. judge that whether background program is carried out service logic wrong, if having, then points out concrete error message, otherwise carry out next step C4;
C4. the model url that is provided with according to the controller the inside is set to the html code snippet of these models url generation on the corresponding DOM.
Advantage of the present invention:
By javascriptMVC, make the developer easy to operate, improve development efficiency, development sequence quickly.Because javascriptMVC is based upon on the ajax (AsynchronousJavaScript+XML), the page is refreshed in the realization part, and also for the user provides more friendly interface, in a word, user experience is fine.
Description of drawings:
Fig. 1 is the process flow diagram that one embodiment of the invention user operates on the page.
Embodiment:
Central idea of the present invention is, javascript realizes the method [being called for short JavaScriptMVC] of MVC as controller, under JavaScriptMVC, and model, view and controller function are as follows:
View-be used for is mutual with the user's, realizes with HTML.
Service logic in model-realization system, and generate the HTML code fragment, realize by JSP.Model is mainly view the partial code fragment is provided, but the control of switching between the layout that not responsible full page shows and the page.
Controller-be the bridge of linking up between model and the view, it determines those models to show to the page.Controller is realized by javascript.
The logic of view and model is fairly simple.And the steering logic more complicated elaborates below in conjunction with accompanying drawing.
As shown in Figure 1, user's concrete steps of on the page, operating:
101. the user carries out concrete operations on the page, call a javascript, realizes that function is as follows:
1011. create a controller object controller earlier
1012. assembling data object
1013. the call back function of controller is set
1014. be provided with controller several (model url, domID)
102. by AJAX, directly call background java, realize that function is as follows:
1021. whether judge the user logins;
1022. execution service logic;
1023. execution model url obtains the code snippet of html;
103. after the background java method is finished,, carry out a javascript method, realize that function is as follows by AJAX call back function function:
1031. it is unusual to judge whether the background program execution has, if unusual, then points out concrete error message.If not unusual, do not carry out next step 1032;
1032. judge whether the user is overtime, if overtime, then eject login frame, please the user login again; If do not have overtime, carry out next step 1033;
1033. judge that whether background program is carried out service logic wrong, if having, then points out concrete error message; Otherwise carry out next step 1034;
1034. according to the model url that the controller the inside is provided with, the html code snippet that these models url is produced is set on the corresponding DOM.This just finishes the variation of page layout.
If controller registered callbacks function is so just carried out this call back function.
This operation comprises increase, revises, and deletion, return-list is checked.
Example is operating as and abandons more specifically
function?addUser(){
var?user={
name:$(″name″).vlaue,
address:$(″address″).value
};
var?controller=new?JSController();
controller.backCallFunc=function(map){
Alert (" increasing employee's success ");
};
var?url=″/os/list.jsp″;
controller.addOneUrl(url,″commentDiv″);
JSService.addUser(user,controller);
Suppose that the user clicks the new user of increase at the page, just carry out the addUser method, addUser finishes following function:
Cheng Chengyi javascript object of assembling data,
Create a javascript controller object, called after controller
To controller the receipt function is set.
(url domID), can be provided with a plurality of in setting to controller.
Calling JSService method addUser, by the ajax technology, is exactly that equivalence is called java method addUser.
Backstage java method addUser carries out following content:
Judge whether the user lands.
Increase new user.
According to the controller content url address has been set, has carried out these url, obtained these url execution results: the html fragment.

Claims (7)

1. a method that realizes MVC is characterized in that;
Realize the MVC model based on javascript as controller,
View-be used for is mutual with the user's, realizes with HTML;
Service logic in model-realization system, and generate the HTML code fragment, realize by JSP;
Controller-be the bridge of linking up between model and the view, it determines those models to show to the page.
2. method according to claim 1 is characterized in that: described model is mainly view the partial code fragment is provided, but the control of switching between the layout that not responsible full page shows and the page.
3. method according to claim 1 is characterized in that: described controller is realized by javascript.
4. method according to claim 1 is characterized in that: comprise the steps:
The first step, the user carries out concrete operations on the page, javascript of WEB server calls,
In second step,, directly call the code snippet that background java realizes obtaining html by AJAX;
In the 3rd step, after background java is finished,, carry out a javascript and realize that the html code snippet that produces is set on the corresponding DOM by the AJAX call back function.
5. method according to claim 4 is characterized in that: the described first step specifically comprises
A1. create a controller object controller earlier;
A2. assemble data object;
A3., the call back function of controller is set
A4., controller is set, model url, domID.
6. method according to claim 4 is characterized in that: in described second step, specifically comprise
B1. judge whether the user logins;
B2. carry out service logic;
B3. execution model url obtains the code snippet of html.
7. method according to claim 4 is characterized in that: in described the 3rd step, specifically comprise
C1. it is unusual to judge whether the background program execution has, if having, then points out concrete error message; If not unusual, carry out next step;
C2. judge whether the user is overtime,, then eject landing frame, please the user land again,, carry out next step if do not have overtimely if overtime;
C3. judge that whether background program is carried out service logic wrong, if having, then points out concrete error message, otherwise carry out next step;
C4. the model url that is provided with according to the controller the inside is set to the html code snippet of these models url generation on the corresponding DOM.
CNA200810111953XA 2008-05-19 2008-05-19 Method for realizing MVC Pending CN101587435A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNA200810111953XA CN101587435A (en) 2008-05-19 2008-05-19 Method for realizing MVC

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNA200810111953XA CN101587435A (en) 2008-05-19 2008-05-19 Method for realizing MVC

Publications (1)

Publication Number Publication Date
CN101587435A true CN101587435A (en) 2009-11-25

Family

ID=41371692

Family Applications (1)

Application Number Title Priority Date Filing Date
CNA200810111953XA Pending CN101587435A (en) 2008-05-19 2008-05-19 Method for realizing MVC

Country Status (1)

Country Link
CN (1) CN101587435A (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102799477A (en) * 2012-07-16 2012-11-28 中兴通讯股份有限公司 Resource access method and apparatus
CN102902537A (en) * 2012-09-19 2013-01-30 厦门亿联网络技术股份有限公司 Embedded WEB model view controller (MVC) development framework based on Fast common gateway interface (CGI) and hypertext markup language (HTML) template
CN103257855A (en) * 2012-12-11 2013-08-21 深圳市梦圆皇宫管理顾问有限公司 MVC (model view controller) based processing system, MVC based processing method and application in facial beautifying software
CN104461509A (en) * 2014-11-10 2015-03-25 浪潮(北京)电子信息产业有限公司 Information interaction framework and method
CN104484182A (en) * 2014-12-25 2015-04-01 广东电子工业研究院有限公司 Elastic extensible multi-data-source mvc (model-view-controller) model architecture
CN104615431A (en) * 2015-02-05 2015-05-13 浪潮集团有限公司 Method and device for achieving Web application
CN104685466A (en) * 2012-08-09 2015-06-03 谷歌公司 Browser-level background page for providing multiple views
CN105487848A (en) * 2014-10-08 2016-04-13 Tcl集团股份有限公司 Display refreshing method and system for 3D applications
CN106339471A (en) * 2016-08-29 2017-01-18 九次方财富资讯(北京)有限责任公司 Method and system for showing page locally-refreshed dual-publicity data web realized based on Ajax request
CN106339264A (en) * 2016-08-29 2017-01-18 九次方财富资讯(北京)有限责任公司 Method and system for showing dual-publicity data web page realized based on Ajax asynchronous call technology
CN106951233A (en) * 2017-03-02 2017-07-14 广州天高软件科技有限公司 Mixed mode smart mobile phone application development framework
CN107092514A (en) * 2016-08-25 2017-08-25 口碑控股有限公司 A kind of content of pages methods of exhibiting and device
CN108287696A (en) * 2018-03-05 2018-07-17 万帮充电设备有限公司 The development approach of Web application frameworks, apparatus and system
CN110580154A (en) * 2019-05-24 2019-12-17 中国银联股份有限公司 access method based on H5 access mode, access assembly and mobile terminal thereof

Cited By (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102799477A (en) * 2012-07-16 2012-11-28 中兴通讯股份有限公司 Resource access method and apparatus
US10303750B2 (en) 2012-08-09 2019-05-28 Google Llc Browser-level background page for providing multiple views
CN104685466B (en) * 2012-08-09 2018-01-23 谷歌公司 For providing the browser level background pages of multiple views
CN104685466A (en) * 2012-08-09 2015-06-03 谷歌公司 Browser-level background page for providing multiple views
CN102902537A (en) * 2012-09-19 2013-01-30 厦门亿联网络技术股份有限公司 Embedded WEB model view controller (MVC) development framework based on Fast common gateway interface (CGI) and hypertext markup language (HTML) template
CN102902537B (en) * 2012-09-19 2016-03-30 厦门亿联网络技术股份有限公司 Based on the embedded type WEB MVC Development Framework of FastCGI and html template
CN103257855B (en) * 2012-12-11 2016-04-06 深圳市梦圆皇宫管理顾问有限公司 A kind of disposal system based on MVC, disposal route and the application in beauty treatment software
CN103257855A (en) * 2012-12-11 2013-08-21 深圳市梦圆皇宫管理顾问有限公司 MVC (model view controller) based processing system, MVC based processing method and application in facial beautifying software
CN105487848B (en) * 2014-10-08 2019-03-19 Tcl集团股份有限公司 A kind of the display method for refreshing and system of 3D application
CN105487848A (en) * 2014-10-08 2016-04-13 Tcl集团股份有限公司 Display refreshing method and system for 3D applications
CN104461509A (en) * 2014-11-10 2015-03-25 浪潮(北京)电子信息产业有限公司 Information interaction framework and method
CN104461509B (en) * 2014-11-10 2018-10-12 浪潮(北京)电子信息产业有限公司 A kind of information interaction system and method
CN104484182A (en) * 2014-12-25 2015-04-01 广东电子工业研究院有限公司 Elastic extensible multi-data-source mvc (model-view-controller) model architecture
CN104615431A (en) * 2015-02-05 2015-05-13 浪潮集团有限公司 Method and device for achieving Web application
CN107092514A (en) * 2016-08-25 2017-08-25 口碑控股有限公司 A kind of content of pages methods of exhibiting and device
CN107092514B (en) * 2016-08-25 2021-06-22 口碑控股有限公司 Page content display method and device
CN106339471A (en) * 2016-08-29 2017-01-18 九次方财富资讯(北京)有限责任公司 Method and system for showing page locally-refreshed dual-publicity data web realized based on Ajax request
CN106339264A (en) * 2016-08-29 2017-01-18 九次方财富资讯(北京)有限责任公司 Method and system for showing dual-publicity data web page realized based on Ajax asynchronous call technology
CN106951233B (en) * 2017-03-02 2020-04-17 广州天高软件科技有限公司 Mixed-mode smart phone application development framework system
CN106951233A (en) * 2017-03-02 2017-07-14 广州天高软件科技有限公司 Mixed mode smart mobile phone application development framework
CN108287696A (en) * 2018-03-05 2018-07-17 万帮充电设备有限公司 The development approach of Web application frameworks, apparatus and system
WO2020238277A1 (en) * 2019-05-24 2020-12-03 中国银联股份有限公司 Access method based on h5 access mode, access assembly thereof and mobile terminal
CN110580154A (en) * 2019-05-24 2019-12-17 中国银联股份有限公司 access method based on H5 access mode, access assembly and mobile terminal thereof
TWI767182B (en) * 2019-05-24 2022-06-11 大陸商中國銀聯股份有限公司 H5-Based Access Components and Mobile Terminals

Similar Documents

Publication Publication Date Title
CN101587435A (en) Method for realizing MVC
CN102325191B (en) Fully automatic treatment method and frame without page refresh
CN103729285A (en) Method, device and system for testing web page
CN102426549B (en) Efficient Web form validation method and framework thereof
CN100512115C (en) Method and system for providing service to user
CN101216838B (en) XML interface configuration file distribute system and method based on WEB marker
CN102855142B (en) A kind of client framework structure based on RIA and its implementation
CN104866512A (en) Method, device and system for extracting webpage content
CN103383645A (en) Code generation method and system
CN102609264A (en) Method and device for generating calling codes by calling application programming interfaces
CN111143207B (en) Method for checking model training notice and training log at mobile terminal
CN110221848A (en) APP method for updating pages, device, electronic equipment and storage medium
CN104375818A (en) System and method for achieving general data form inputting through configuration files
CN102231106A (en) Method for generating application code of mobile and general development platform
CN106997298A (en) A kind of application resource acquisition methods and device
CN102567400B (en) Method for realizing Web visit and Web server
CN103678343B (en) The method and apparatus of prompting webpage load progress
US11860963B2 (en) Enhanced methods and systems for automated skill generation and management
CN111221729B (en) Automatic testing method and system for separating platform service from testing service
CN105404514A (en) JavaScript rendering method and apparatus
CN110750415A (en) Interface service configuration method, device, medium and computer equipment
CN101937335A (en) Method for generating Widget icon, method for generating Widget summary document and Widget engine
CN102880492B (en) A kind of XML script resolver based on AS and method thereof
US20220300262A1 (en) Method for constructing, running and implementing cross-platform application, terminal, server and system
CN104834715A (en) Website generating method and system based on components and container

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Open date: 20091125