【正文】
system of UEST of China ( References [1] Erich Gamma. Design Patterns. . AddisonWesley Pub Co. [2] Didier Martin. Professional XML. . Wrox Press. [3] Stephen T. Mohr. Designing Distributed Applications with XML, ASP, IE5, LDAP amp。 Lu Xianliang, the professor of UEST of China, advisor of .。 MSMQ. . Wrox Press. [4] Sun Microsystems Inc. JavaTM Servlet and JavaServer PagesTM Spec fications. [5] Sun Microsystems Inc. JavaServer PagesTM Standard Tag Library Specification 原文一: A Novel Web Application Frame Developed by MVC Luo GuangChun WangYanhua Lu Xianliang Hanhong* (Information Center of UEST of China, ChengDu, China 610054) Abstract The MVC (Model/View/Controller) design pattern was developed in Smalltalk80 and widely used in software design. This paper introduces a novel Web application frame based on MVC. This frame separates the transaction logic from the presentation format. It also improves the system maintainability, scalability and performance by using the module database, template database, messaging object and buffer queue. Key words: MVC, Design Pattern, Web Application 1. Introduction Web application system is a transaction system based on B (rowser)/S(erver) model. It exploits many kinds of dynamic Web developing technologies. At present, Web application developing patterns and tools are one of the topics of the software design. They directly influence several key factors such as maintainability, scalability, stability and the security. In this paper, the purpose of MVC[1]based Web application design pattern is to resolve the two factors – maintainability and scalability, which are the stubborn problems in the Web application development. By introducing the MVC design pattern into the Web application development, the implementation of system transaction logic can be separated from the system presentation. MVC consists of three kinds of objects. 1) the Model: is the application object, 2) the View: is its screen presentation, 3) the Controller: defines the way the user interface reacts to user input. Before MVC, user interface designs tended to lump these objects together. However, MVC decouples them to increase the flexibility and reuse. MVC decouples views and models by establishing a “subscribe/notify” protocol between them. A view must ensure that its appearance reflects the state of the model correctly. Whenever the model’s data changes, the model notifies views that depend on it. In response, each view gets an opportunity to update itself. This approach lets you attach multiple views to a * Luo Guangchun, the . of UEST of China。此外 ,利用模型數(shù)據(jù)庫(kù)和 LPM數(shù)據(jù)庫(kù),這個(gè)更系統(tǒng)的靈活性、可維護(hù)性和可擴(kuò)充 性得到了顯著提高。框架解決是一個(gè)大問(wèn)題 ,曾困惑很多網(wǎng)絡(luò)開(kāi)發(fā)者。 從上述對(duì)系統(tǒng)框圖的分析 ,我們可以做一個(gè)結(jié)論。其原 因是 ,這些腳本語(yǔ)言都有天生的缺陷 (例如 ,他們卻沒(méi)有有好的對(duì)象支持和事件響應(yīng)機(jī)制等 );他們不能令人滿意地縮短網(wǎng)絡(luò)應(yīng)用系統(tǒng)的執(zhí)行邏輯。最后 ,混沌編碼會(huì)帶來(lái)一系列的問(wèn)題。因此,它要求開(kāi)發(fā)者有很強(qiáng)的編程能力 (他們必須非常熟悉執(zhí)行規(guī)劃和界面設(shè)計(jì) )。這主要由于舊設(shè)計(jì)模式對(duì)系統(tǒng)邏輯框架的獨(dú)立性的不足之處。在下一節(jié) ,我們將向你展示一個(gè)簡(jiǎn)單的例子去解釋如何在三層 MVC模式的過(guò)程通過(guò)增加中間執(zhí)行步驟擴(kuò)大系統(tǒng)框架。因?yàn)槲覀円呀?jīng)把控制器分為 3個(gè)部分, MVC三層 (模型 /視圖 /控制器 )的聯(lián)系變得更加寬松。當(dāng)系統(tǒng)框架已確定,各部分驚人的發(fā)現(xiàn)開(kāi)發(fā)的相似。(過(guò)程見(jiàn)圖 2) 通過(guò)分析系統(tǒng)框架 ,可以看出整個(gè)系統(tǒng)完全符合 MVC設(shè)計(jì)模式。例如 ,模式中心不直接從模型數(shù)據(jù)庫(kù)調(diào)用對(duì)象或模塊。它根據(jù)給定數(shù)據(jù)類型和執(zhí)行邏輯選擇適當(dāng)?shù)倪壿嬳?yè)模塊 ,然后封裝邏輯頁(yè)的輸出模塊到 HTTP響應(yīng)并將發(fā)布到客戶端。此外 ,這種類型的服務(wù)器腳本可以很容 易由客戶開(kāi)發(fā)人員在 UI(user interface)設(shè)計(jì)階段理解, whatyouseeiswhatyouget(所見(jiàn)即所得 )工具也很容易開(kāi)發(fā)。一個(gè) LPM的功能是很簡(jiǎn)單的 :它只需要在沒(méi)有被得到執(zhí)行邏輯和原數(shù)據(jù)內(nèi)容的情況下給定數(shù)據(jù)類型。 LPM是實(shí)施描述的某一種數(shù)據(jù)類型的項(xiàng)目集合,它可以當(dāng)成是一個(gè)或一組磁盤(pán)文件。此外 ,每個(gè)對(duì)象或模塊只需要關(guān)心如何實(shí)現(xiàn)給定的事務(wù)的邏輯以及如何獲得必要的 數(shù)據(jù)而不提交這些數(shù)據(jù)。當(dāng)模式中心接收到的執(zhí)行消息 ,它根據(jù)封裝在信息里的執(zhí)行邏輯選擇合適的對(duì)象或模塊。模型數(shù)據(jù)庫(kù)包括大量的對(duì)象和模塊。 其次 ,我們考慮模型中心和模型數(shù)據(jù)庫(kù)。而 SAX接口以高效率和更少的系統(tǒng)資源占用率著稱。使用 DOM可以實(shí)現(xiàn)結(jié)構(gòu)搜索。另一種是使用 SAX(Simple API for XML)接口。當(dāng)應(yīng)用程序系統(tǒng)開(kāi)機(jī) ,這樣需要 DOM解析器分析整個(gè)數(shù)據(jù)庫(kù)備案后載入內(nèi)存。 SYSController有兩種方法搜索數(shù)據(jù)庫(kù)。而 SYSController可以搜索系統(tǒng)描述數(shù)據(jù)庫(kù)。這個(gè)數(shù)據(jù)庫(kù)描述了不同的執(zhí)行邏輯與不同的用戶請(qǐng)求。他們負(fù)責(zé)接收用戶的要求 和根據(jù)這些請(qǐng)求搜索有關(guān)的執(zhí)行邏輯。通過(guò)這些控制對(duì)象 /類和數(shù)據(jù)庫(kù) ,下文將解釋部分的設(shè)計(jì)思想和該系統(tǒng)框架的實(shí)現(xiàn)機(jī)制。 圖 2中顯示 ,這一系統(tǒng)框架包含三個(gè)內(nèi)核控制對(duì)象 /類 (SYSController, Model Center, and LPM(Logical Page Module) Center)和它們的核心數(shù)據(jù)庫(kù) (system description database, model database, and LPM database)。因?yàn)檫@一過(guò)程 ,Servlet 本身已實(shí)現(xiàn)非常復(fù)雜的執(zhí)行邏輯,對(duì)于體系的發(fā)展和維護(hù)這是正是一個(gè)棘手的問(wèn)題。但制仍然存在某些限,例如 ,盡管 JSP Model2 已經(jīng)實(shí)施采用 MVC設(shè)計(jì)模式的基本理念,三個(gè)層次之間的相互關(guān)系(Servlet,Java Bean/ EJB 和 JSP)仍然封閉。 ?控制器 (控制層 ):Servlet受到 網(wǎng)頁(yè)上的 用戶的輸入并執(zhí)行有關(guān) 的操作 (呼叫相應(yīng)的EJB組件 ),給出了相關(guān) 視圖 ,所以 JSP會(huì)呈現(xiàn)這些結(jié)果。 圖 1顯示了 MVC的 機(jī)制 : ?模型 (數(shù)據(jù)層 ):它是封裝到企業(yè) JavaBean。直到 JSP Model2版 ,這種 情況并沒(méi)有受到任何改善。 Han Hong, the . of UEST Of China 腳本語(yǔ)言的功能太弱。 Wang Yanhua, the Master of the UEST of China。 因 此 ,這兩種方法 使 采用 MVC分離三層 模式 十分難以實(shí)現(xiàn)。腳本語(yǔ)言出現(xiàn)后 ,變成了 腳本語(yǔ)言編寫(xiě)的程序 嵌入到 HTML文本中 。早期的 CGI程序使用字符串輸出創(chuàng)造了 HTML內(nèi)容。 雖然 MVC的設(shè)計(jì) 模式已經(jīng) 在 smalltalk80中 提出了 ,并 廣泛應(yīng)用于軟件設(shè)計(jì) ,介紹它 到網(wǎng)頁(yè)應(yīng)用程序開(kāi)發(fā) 卻仍很 困難 的。這個(gè)方法可以讓你附上 一個(gè)模型的 多 個(gè) 視圖 以便 提供不同的報(bào)告。每當(dāng)模型的數(shù)據(jù) 發(fā)生 改變 ,視圖會(huì)得到相應(yīng)的通知 。 MVC把視圖和模型 獨(dú)立開(kāi)來(lái) ,在它們之間 建立了 “ subscribe/notify” 協(xié)議。 在出現(xiàn) MVC之前 ,用戶 界面的 設(shè)計(jì) 傾向于 把這些東西 做 在一 起。 MVC由三種對(duì)象 組成 。 本文中, 基于 MVC[1]的網(wǎng)絡(luò)應(yīng)用程序的設(shè)計(jì)模式是為解決這兩類 因素 —— 擴(kuò)展性 和 可維護(hù)性 這些不易處理的問(wèn)題 。目前 ,軟件設(shè)計(jì) 的主題之一是 網(wǎng)絡(luò)應(yīng)用 開(kāi)發(fā) 模式和工具的。 關(guān)鍵詞 :MVC、設(shè)計(jì)模式、 網(wǎng)絡(luò)應(yīng)用程序 網(wǎng)絡(luò)應(yīng)用系統(tǒng)是一個(gè)基于 B(rowser)/ S(erver)模型 應(yīng)用系統(tǒng) 。這種框架把實(shí)施邏輯與表現(xiàn)形式獨(dú)立開(kāi)來(lái)。譯文一: 一種新的網(wǎng)絡(luò)應(yīng)用程序開(kāi)發(fā)框架 —— MVC* 摘要 MVC(Model/View/Controller)的設(shè)計(jì)模式出現(xiàn)在在 Smalltalk80,并在軟件的設(shè)計(jì)中廣泛應(yīng)用。本文介紹一種基于 MVC框架的的新網(wǎng)絡(luò)應(yīng)用程序。它也提高了系統(tǒng)的可維護(hù)性 ,可擴(kuò)展性以及使用模塊數(shù)據(jù)庫(kù)備案、模板數(shù)據(jù)庫(kù) ,通訊對(duì)象和緩沖隊(duì)列的性能。它利 用多種動(dòng)態(tài)網(wǎng)頁(yè) 開(kāi)發(fā) 技術(shù)。 它 們直接影響 系統(tǒng) 的幾個(gè)關(guān)鍵因素 ,比如可維護(hù)性 、 可擴(kuò)展性、穩(wěn)定 性 和安全 性 。 把 MVC設(shè)計(jì)模式引入網(wǎng)絡(luò)應(yīng)用程序開(kāi)發(fā) ,執(zhí)行 邏輯可以 獨(dú)立于 系統(tǒng)的 表現(xiàn)形式 。 1)模型 :是應(yīng)用對(duì)象 , 2)視圖 :是它的屏幕的 顯示 ,3)控制器 : 定義用戶界面 并對(duì) 輸入的信息 做出響應(yīng) 。然而 ,MVC獨(dú)立了它 們 , 增加 系統(tǒng)的 靈活性和 可 重用 性 。一個(gè)視圖必須確保其 正確反映 模型的狀態(tài)。作為回應(yīng) ,每個(gè)視圖 都會(huì)有 更新 自 身 的 機(jī)會(huì)。你也可以 不改變?cè)?模型 同時(shí) 創(chuàng)建新的 視圖 。主要由于以下兩個(gè)因素 :1)首先 ,很難 獨(dú)立 來(lái)自 HTML的編程語(yǔ)言。 默認(rèn)的 ,將 HTML文本 分成幾份 ,然后 把 他們 嵌 入 到 CGI程序 中 。然而 ,這兩種方法有一個(gè)共同的不足 ,使他們不能 完全 獨(dú)立 于 HTML文本 。 2)第二 , * Luo Guangchun, the . of UEST of China。 Lu Xianliang, the professor of UEST of China, advisor of .。他們?nèi)狈σ恍┍匾募夹g(shù)支持 來(lái) 采用 MVC的設(shè)計(jì)模式 ,如消息機(jī)制和事件回應(yīng)機(jī)制。依靠強(qiáng)大的Java語(yǔ)言功能 ,JSP Model2[4]某種程度 上 實(shí)行 MVC設(shè)計(jì)理念。 ?視圖 (表示層 ):JSP負(fù)責(zé)的網(wǎng)頁(yè)方式 ,如報(bào)告的格式 ,分頁(yè)等。 JSP Mo