




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、 中文翻譯 基于Java技術(shù)的Web應(yīng)用設(shè)計模型的比較研究 來源:School of Computer Science and Engineering University of New South Wales Sydney, NSW 2052, Australia 作者:Budi Kurniawan and Jingling Xue 摘要 Servlet技術(shù)是在建立可擴(kuò)展性Web應(yīng)用中被應(yīng)用最廣泛的技術(shù)。在運(yùn)用JAVA技術(shù)開發(fā)Web應(yīng)用中有四種模型,分別是:Model 1、Model 2、Struts和JavaServer Faces JSF。Model 1使用一連串的JSP頁面,Model
2、 2采用了模型,視圖,控制器MVC模式。Struts是一個采用了Model 2設(shè)計模型的框架,JSF是一種支持ready-to-use組件來進(jìn)行快速Web應(yīng)用開發(fā)的新技術(shù)。Model 1對于中等和大型的應(yīng)用來說很難維護(hù),所以不推薦使用。本文通過利用Model 2、Struts和JSF這三種模型分別構(gòu)建三個不同版本的在線商店應(yīng)用程序來比較和評價這三種模型在應(yīng)用程序開發(fā)和性能上的差異。 1.緒論 當(dāng)今Web應(yīng)用是一種展現(xiàn)動態(tài)內(nèi)容的最普遍的方式。構(gòu)建Web應(yīng)用有許多種方法,其中最流行的是Servlet技術(shù)。這種技術(shù)的流行是因?yàn)樗菴GI、PHP等其他技術(shù)更具優(yōu)越性。然而Servlet對于開發(fā)來說還是
3、麻煩的,因?yàn)樗趥魉虷TML標(biāo)簽時需要程序員將他們組合成為一個字符串對象,再將這個對象傳給瀏覽器。同樣的,對于輸出的一個很小的改動也要求Servlet被重新編譯。基于這個原因SUN公司發(fā)明了JavaServer Pages JSP技術(shù)。JSP允許HTML標(biāo)簽和Java代碼混合在一起,每個頁面將被轉(zhuǎn)化為一個Servlet,一個JSP就是一個Servlet,而且編譯將在JSP頁面第一次被請求時自動進(jìn)行改變輸出也不需要重新編譯。另外通過使用JavaBean和定制標(biāo)簽庫,JSP能夠?qū)⒈硎九c業(yè)務(wù)邏輯相分離。現(xiàn)今基于JAVA的Web應(yīng)用開發(fā)標(biāo)準(zhǔn)是將servlets與JSP結(jié)合在一起。隨后出現(xiàn)了許多種設(shè)計模
4、型用來。JavaServer Faces JSF和Struts、Model 2、Model 1應(yīng)用。servlet/JSP構(gòu)建 而不使用JSPModel 1只使用Model 2最早是在JSP規(guī)范中被提及的。和Model 1的使用是有條件和Model 2。JSP與servletModel 1servlet,Model 2則結(jié)合了則是開發(fā)中型和大型應(yīng)用適合與開發(fā)原型和非常小的應(yīng)用,Model 2的。Model 1框架的開越來越被行業(yè)所接受,一個建立Struts推薦的設(shè)計模型。由于Model 2提供了模型、視圖、控制器中的通過為Model 2源項(xiàng)目也因此被啟動了。Struts Model 2。控制器
5、來完善提供了更好的頁面導(dǎo)航管理機(jī)制和一些定制標(biāo)簽庫,能夠進(jìn)行更另外Struts快速的開發(fā)。盡管它學(xué)習(xí)難度大,并且實(shí)際上它沒有在任何的規(guī)范中被定義,但是JSR-127的Faces是在JCPJavaServer 它還是作為Model 2的一種替代獲得了流行。應(yīng)用的最Java Web規(guī)范下被建立。Sun公司力推這項(xiàng)技術(shù),希望它能夠成為構(gòu)建組件的支持,比如,可擴(kuò)展用戶接ready-to-use終模型。JSF最重要的特性是對servlet/JSP管理機(jī)制。數(shù)據(jù)轉(zhuǎn)換和JavaBean口組件、簡易的頁面導(dǎo)航、輸入驗(yàn)證、在開發(fā)時間上提供了更好JSF程序員面臨的問題是選擇最合適的設(shè)計模型。明顯的的開銷所帶來的性
6、能下降而不愿采用這種JSF然而,有些人擔(dān)心實(shí)施的解決方案。 技術(shù)。 分別構(gòu)建三個不同版本的在線商店應(yīng)用和JSF我們使用Model 2、 Struts比較的參數(shù)是代碼的行數(shù)、類的數(shù)目和性能測試結(jié)果。 我們研究哪種設(shè)計模型能夠進(jìn)行最快速的開發(fā)。我們評估基于這些模型的應(yīng)用的性能。我們提供一些建議來完善現(xiàn)有的設(shè)計模型使得開發(fā)速度更快。 文章的余下部分組織如下 第二部分討論了Web開發(fā)中的問題,第三部分解釋了三個設(shè)計模型如何來解決這些開發(fā)問題,第四部分詳細(xì)介紹了試驗(yàn)所需要的硬件和軟件,第五部分給出試驗(yàn)的結(jié)果并進(jìn)行分析,第六部分回顧相關(guān)工作,第七部分得出結(jié)論并提出了一些改進(jìn)現(xiàn)有設(shè)計模型的建議。 2.Web
7、開發(fā)中的問題 所有的Java開發(fā)都使用Servlet技術(shù)作為基礎(chǔ)技術(shù)。同樣的所有的Java Web應(yīng)用都有一些問題需要解決: 1.用戶接口是在客戶瀏覽器上呈現(xiàn)出的HTML標(biāo)簽。任何在應(yīng)用中使用的服務(wù)器端組件都必須被編碼成為正確的HTML標(biāo)簽。除了顯示內(nèi)容和數(shù)據(jù)外,用戶接口還負(fù)責(zé)接收用戶的輸入。 2.用戶的輸入必須要驗(yàn)證。輸入的驗(yàn)證有兩種類型:服務(wù)器端和客戶端。顧名思義,服務(wù)器端的輸入驗(yàn)證是在輸入的數(shù)據(jù)到達(dá)服務(wù)器后在服務(wù)器上進(jìn)行的??蛻艋蚱渌_本語言。利用JavaScript端的輸入驗(yàn)證是在瀏覽器上完成的,一般使用 無論是否存客戶端進(jìn)行輸入驗(yàn)證的好處是反應(yīng)迅速,而且能夠減輕服務(wù)器的負(fù)載。因?yàn)闊o法
8、保證用戶的瀏在客戶端輸入驗(yàn)證,服務(wù)器端的輸入驗(yàn)證是一定要執(zhí)行的。 覽器的腳本特性被打開,而且惡意用戶能夠很輕松的繞過客戶端的驗(yàn)證。 的形式出項(xiàng)的。模型對象應(yīng)用中模型對象是以JavaBean在基于Java的Web3.一個模型對象能夠用來綁定一個組件的值MVC設(shè)計模型的模型部分。組成了基于以備下階段使用。此外它能夠封裝需要執(zhí)行的業(yè)務(wù)邏輯。 4.大多數(shù)的Web應(yīng)用都包含多個頁面,能夠使用戶從一個頁面跳轉(zhuǎn)到另一個頁面。所有的基于MVC的設(shè)計模式都使用Servlet作為控制部分。這個Servlet也作為進(jìn)入應(yīng)用的唯一入口。當(dāng)前的請求之后哪個頁面會被顯示取決于請求參數(shù)的具體值。管理頁面導(dǎo)航是至關(guān)重要的。
9、應(yīng)用設(shè)計模型Web3.Model 2設(shè)計模型是基于模型、視圖、控制器、MVC設(shè)計模式的。正如Burbeck所解釋的,在MVC中有三個主要模塊:控制器、視圖和模型??刂破髯鳛閼?yīng)用的中心,所有的用戶交互都要通過它。視圖包含了應(yīng)用的顯示,而模型用來存儲數(shù)據(jù)和封裝應(yīng)用的業(yè)務(wù)邏輯。隨后,Struts框架提供了一個通用框架能夠容易的構(gòu)建Model 2應(yīng)用。最主動的是同樣使用MVC設(shè)計模式的JSF。在之后的章節(jié),我們將來討論這三種設(shè)計模型,并且說明每一種設(shè)計模型是怎樣來解決之前提到的開發(fā)問題。 Model 2 一個基于Model 2設(shè)計模型的Java Web應(yīng)用有一個作為控制部分的servlet稱為控制器s
10、ervlet。所有的請求首先被這個servlet處理,它通過RequestDispatcher對象將請求迅速的分派到合適的視圖。在Model 2中視圖是通過JSP頁面來表現(xiàn)的。JavaBean作為Model 2 的模型部分,用來在應(yīng)用中存儲數(shù)據(jù)。除了存儲數(shù)據(jù)JavaBean還用來封裝業(yè)務(wù)邏輯。每個HTTP請求都帶有一個行為參數(shù),用來指出哪個視圖指派給這個請求。程序員必須在所有的JSP頁面中為用戶接口編寫HTML標(biāo)簽代碼,并且編寫輸入驗(yàn)證代碼。此外,模型對象被單獨(dú)的JSP頁面所管理。 Struts Struts servlet設(shè)計模型的一個改進(jìn)。它提供了一個默認(rèn)的控制器框架是Model 2文件中
11、編XMLStruts使得程序員不用非得去編寫一個。允許在應(yīng)用配置文件一個除了更簡單的改變導(dǎo)航規(guī)則不需要重新編譯。寫導(dǎo)航規(guī)則來減輕頁面導(dǎo)航的任務(wù),元素。這些標(biāo)簽中的HTML頁面導(dǎo)航,Struts還提供了定制標(biāo)簽庫來定義標(biāo)簽代表支持國際化,能夠顯示本地化的錯誤消息。就像Struts一些用來處理異常,而且程序員必須編寫輸入StrutsStruts使用JavaBean作為模型。此外2Model 一樣, 驗(yàn)證代碼。 JSF 是整個稱為FacesServlet。這個Servlet同樣使用了一個控制器JSFservlet作為模JSP頁面作為它的視圖,使用JavaBeanJSF應(yīng)用的唯一入口。JSF同樣使用r
12、eady-to-use提供了能夠?qū)懭隞SP頁面的與Model 2和Struts不同,JSF型對象。建立了一個組件樹JSF應(yīng)用中的頁面的調(diào)用,F(xiàn)acesServlet的用戶接口組件。在對JSF的事件驅(qū)動。來顯示JSP頁面的請求。大部分的組件還能夠觸發(fā)事件來構(gòu)成文即允許在一個應(yīng)用控制文件,XML,JSF使用了和Struts類似的方法,于頁面導(dǎo)航 件中定義導(dǎo)航規(guī)則。的JSF的servlet/JSP應(yīng)用的不同在于JSF是事件驅(qū)動的。JSF應(yīng)用與非JSF這些組用來服務(wù)諸如表單和輸入框等JSP頁面,Web組件。用戶接口是一個或多個一個組件能夠嵌套在另一個組件件以JSF定制標(biāo)簽的形式出現(xiàn)而且能夠保存數(shù)據(jù)。J
13、avaBean應(yīng)用中,使用中,有可能形成一個組件的樹狀結(jié)構(gòu)。在普通的servlet/JSP 來存儲用戶輸入的數(shù)據(jù)。運(yùn)行環(huán)境4. 以下是我們實(shí)驗(yàn)的軟硬件詳細(xì)描述。 容器 Servlet 容器中運(yùn)行的,在應(yīng)用中它一個引擎用來處理接踵servletJava Web應(yīng)用是在一個來自請求。在這個試驗(yàn)項(xiàng)目中,我們使用Tomcat而來的請求資源的HTTP容器容器,版本號是?;旧弦粋€servletApache軟件基金會的開源的servlet 通過執(zhí)行下面的任務(wù)來處理一個servlet: HttpRequest創(chuàng)建一個對象 對象HttpResponse創(chuàng)建一個傳遞HttpRequest、HttpRespons
14、e對象來調(diào)用Servlet接口的service方法 測試用客戶端 為了進(jìn)行性能測試,我們使用同樣來自Apache軟件基金會的來模擬多用戶。JMeter允許用戶選擇一定數(shù)量的線程來執(zhí)行測試。每個線程模擬了一個不同的用戶。JMeter來能允許我們選擇完成一次測試的測試次數(shù)。使用JMeter來測試一個Web應(yīng)用。你只要直接向某個IP地址、上下文路徑和端口號發(fā)出請求。你也可以將請求參數(shù)包含在HTTP請求中。對于一個測試,JMeter將服務(wù)器的響應(yīng)時間以毫秒的形式輸出。從響應(yīng)時間,我們能夠得到服務(wù)器執(zhí)行服務(wù)的每秒命中次數(shù)。 硬件 為了得到最大的性能度量精度,我們使用不同的計算機(jī)來進(jìn)行應(yīng)用的測試。運(yùn)行應(yīng)用
15、的是一臺XP計算機(jī),它的配置如下:Intel Core 1GHz CPU 、1G RAM。測試用客戶端是運(yùn)行JMeter的Windows2000計算機(jī),具體配置如下:Intel Core 1GHz CPU、 1G RAM。 5.結(jié)論 我們得到兩類實(shí)驗(yàn)結(jié)果:開發(fā)的難易程度和性能。開發(fā)的難易程度比較了類的數(shù)目和代碼的行數(shù)。這些數(shù)目顯示了遵從某個設(shè)計模型來開發(fā)一個應(yīng)用的難易程度。一個應(yīng)用包含較少的類和較少的代碼行數(shù)說明應(yīng)用相對而言更容易構(gòu)建。一個 應(yīng)用包含較多的類說明應(yīng)用需要花費(fèi)更多的時間來開發(fā)。性能度量結(jié)果是通過比較這兩個操作來獲得的。查找操作是一個應(yīng)用中最普通的操作以及瀏覽操作。 應(yīng)用開發(fā)的難易
16、程度 就如表1顯示的,應(yīng)用Model 2設(shè)計模型需要花費(fèi)最多的努力。使用Struts能夠使問題減輕一點(diǎn),使用JSF最省力。Model StrutJS#ClasseServle7#Line#ClasseBea3434#Line34 999#ClassesJSP 534733#Lines809 3#ClassesOthers1012 271430#Lines590 21Total28#Classes31 11531821#Lines1511 表1 應(yīng)用中類的數(shù)目和代碼行數(shù) Model 2 設(shè)計模型的特點(diǎn)是存在一個控制器servlet和多個JavaBean類,作為模型及JSP頁面作為視圖。控制器類通
17、過一系列的if語句來負(fù)責(zé)頁面導(dǎo)航規(guī)則。Model 2程序員還必須為輸入驗(yàn)證編寫代碼,在這個實(shí)驗(yàn)中是通過在內(nèi)部編寫許多定制標(biāo)簽庫來完成的。在Model 2設(shè)計模型中的其它類是定制標(biāo)簽庫,這些標(biāo)簽是用來負(fù)責(zé)輸入驗(yàn)證和數(shù)據(jù)顯示的。實(shí)際上輸入驗(yàn)證使用了590行代碼,大約是所有代碼的30%。 在Struts應(yīng)用中,控制器servlet是由框架提供的,所以Struts程序員不用編寫它,節(jié)省了時間。然而,他仍然需要在應(yīng)用控制文件中編寫導(dǎo)航規(guī)則,這比編寫一個servlet容易些,因?yàn)閼?yīng)用控制文件可以用文本編輯器編輯,不必編譯。雖然Struts框架提供了錯誤處理機(jī)制,但仍然需要手工編寫輸入驗(yàn)證。用來進(jìn)行輸入驗(yàn)證
18、的類的數(shù)量和代碼的行數(shù)與Model 2應(yīng)用的很相似。Struts中其他的類是Action類用來調(diào)度請求到默認(rèn)的控制servlet。 在JSF中,提供使用驗(yàn)證組件而不用編寫輸入驗(yàn)證。所以JSF應(yīng)用開發(fā)人員可以跳過這個任務(wù)。此外頁面導(dǎo)航和Struts相同,都是使用一個應(yīng)用控制文件。在JSF中其他的類是ContextListener、ActionListener和數(shù)據(jù)庫工具類。 性能度量 對于每一個操作,通過1-10個并發(fā)用戶,我們來測量服務(wù)器的響應(yīng)時間(以毫秒形式)每個用戶在JMeter中設(shè)定了一定數(shù)量的線程。每次測試進(jìn)行10次,取平均值。每個操作在下面的章節(jié)中討論。 查詢操作 查詢操作,其名稱或
19、描述與關(guān)鍵字匹配。它將執(zhí)行一個SQL的SELECT語句。圖2比較了三個版本的應(yīng)用的查詢操作。 圖2 查詢操作的性能比較 在Model 2應(yīng)用中,對于一個用戶,服務(wù)器平均的響應(yīng)時間是173毫秒,對于10個用戶是919毫秒。在Struts應(yīng)用中,相對地,其值是189毫秒和900毫秒,在JSF中則是210毫秒和932毫秒。響應(yīng)時間隨著并發(fā)用戶數(shù)成比例的增加,說明了服務(wù)器仍然能夠應(yīng)付裝載。 Model 2應(yīng)用開銷最小,所以它的平均性能比Struts和JSF更好。然而,Struts的性能同Model2 的相同,這是因?yàn)榉?wù)器有足夠的內(nèi)存用來加載運(yùn)行Struts需要的Struts庫。同時,應(yīng)該注意到Str
20、uts中的頁面導(dǎo)航規(guī)則是加載和存儲在一個叫ActionMapping的對象中。因此,給出一個請求參數(shù),導(dǎo)航到下個頁面是通過查找得到的。另一方面,給出一個請求參數(shù),Model 2應(yīng)用是利用一系列的if語句來得到下一個頁面的導(dǎo)航。 在幾乎所有的并發(fā)用戶數(shù)字中,JSF應(yīng)用的性能都稍遜于其他應(yīng)用。這可能是由于JSF將時間消耗在為每個請求構(gòu)建一顆組件樹上。但JSF的服務(wù)器響應(yīng)時間與其他應(yīng)用差距并不明顯。 瀏覽操作 三個版本的瀏覽操作,如同查詢操作,將執(zhí)行一個SQL SELECT語句。圖3這個操作的測試結(jié)果。 圖3 瀏覽的性能比較 平均來說,Model 2應(yīng)用的性能最好,因?yàn)樗哂凶钌俚拈_銷。對于是一個用
21、戶服務(wù)器的平均響應(yīng)時間是111毫秒,10個用戶是899毫秒。Struts應(yīng)用有著同樣的性能,對于是一個用戶服務(wù)器的平均響應(yīng)時間是180毫秒,10個用戶是920毫秒。JSF則稍落后與其他兩個應(yīng)用,相對地,它的時間是190毫秒和1009毫秒。響應(yīng)時間隨著并發(fā)用戶數(shù)成比例的增加,意味著服務(wù)器能很好地服務(wù)這些用戶。瀏覽地平均性能測量結(jié)果同查詢操作很相似,這是因?yàn)檫@兩種數(shù)據(jù)庫操作類似。 6.相關(guān)工作 使用servlet、PHP(版本 3)、通用網(wǎng)關(guān)接口(CGI)來比較基于數(shù)據(jù)庫的Web應(yīng)用的性能。經(jīng)過執(zhí)行從MySQL數(shù)據(jù)庫返回數(shù)據(jù)的一系列的基準(zhǔn)測試,發(fā)現(xiàn)Java servlet使用持久數(shù)據(jù)庫連接的方案性
22、能最佳。PHP3使用持久數(shù)據(jù)庫連接相對于CGI方案而言性能相當(dāng)不,也同樣提到了使用Java servlet的優(yōu)勢。根據(jù)這些作者,Java servlet是迎合電子商務(wù)(比如在線商店)需求的最佳選擇,而且能夠在高交互式模式中處理客戶請求。 比較PHP4、Java servlet、和EJB。使用兩個應(yīng)用來測試了這三種結(jié)構(gòu),研究顯示了PHP4比Java servlet更有效,而EJB的性能比servlet差。然而,注意到作為Java方案的一部分的servlet提供了適應(yīng)性,能夠移植到不同操作系統(tǒng)的其他系統(tǒng)上。 7.結(jié)論 應(yīng)最慢但性能最好;Struts構(gòu)建Web應(yīng)用最迅速:Model 2我們發(fā)現(xiàn)使用J
23、SF 用在計較中處于其他兩種設(shè)計模型中間。 我們提出了一些建議技術(shù)和增強(qiáng)基于這些設(shè)計模式Servlet用來大體上改善 的應(yīng)用的性能。沒有基于任何規(guī)范,也沒有文檔來討論它的內(nèi)部工作方式。因此,1.Struts 很難知道哪些實(shí)現(xiàn)了以及哪些改善了。也沒有在即將到來的中提及。Servlet技術(shù),規(guī)范沒有定義任何的緩存機(jī)制,2. 應(yīng)用的內(nèi)容具有動態(tài)性,但有寫內(nèi)容也不是經(jīng)常去改變了。比如,盡管Web在在線商店的應(yīng)用中,用戶可以瀏覽的商品種類可能每隔一個月才變動一將浪費(fèi)次。如果這些半靜態(tài)的內(nèi)容必須每次在需要的時候從數(shù)據(jù)庫中獲取,程序員通過編寫一個對象緩存某些內(nèi)容來實(shí)現(xiàn)緩大量的編程資源。Servlet 存。然
24、而,只要沒有緩存標(biāo)準(zhǔn),許多程序員將反復(fù)的寫相同的代碼段。中是硬編碼的。這意主要的缺點(diǎn)是頁面導(dǎo)航規(guī)則在控制器servlet3.Model 2 解決這個重新編譯。味著程序流程的任何微小的改動就需要控制器servlet在控制提供一個映射器來讀取頁面導(dǎo)航規(guī)則。問題的方法是在應(yīng)用啟動時,方法中很容易添加代碼。這個方法只執(zhí)行一次,就是在init器servlet的如果屬性文件在每次改動后需要重新讀取,首次被載入內(nèi)存的時候。servlet將它于先前讀入的文件比程序員可以在每次請求時檢查屬性文件的時間戳,較。如果它比之前讀入的文件的時間戳更新,則重新構(gòu)建映射器。這個特性這個可以在上下文對象的初始化參數(shù)中開啟或者
25、關(guān)閉。從開發(fā)的角度來講,特性應(yīng)該開啟。在部署時,這個特性應(yīng)該關(guān)閉。使用屬性文件來存儲頁面導(dǎo)它將在每次請求時消耗if語句,航規(guī)則還可能避免在控制器中的一連串的Value值,將跳轉(zhuǎn)頁面作為將請求參數(shù)作為時間??梢允褂靡粋€HashMap,Key值。這個設(shè)計模型的另一個缺陷是缺少標(biāo)準(zhǔn)的輸入驗(yàn)證組件和用戶接口組 JSF中得到解決。件,而這些將在頁面導(dǎo)航管理、用戶接口:4.JSF解決了開發(fā)Web應(yīng)用中的大部分問題,比如 組件和輸入驗(yàn)證組件。然而,由于這項(xiàng)技術(shù)仍然很年輕,還沒有太多的用戶JSFservlets/JSP頁面相結(jié)合。的強(qiáng)迫了程序員將接口可用,JSF和非JSF應(yīng)用的行為,就像JSF是事件驅(qū)動的,J
26、SF程序員通過編寫事件監(jiān)聽來決定版本中,通常有兩類事件能夠被觸Swing應(yīng)用中的監(jiān)聽器一樣。在JSF 但這已經(jīng)能在應(yīng)用和用戶之間提供ValueChangedEvent:ActionEvent發(fā)和, 足夠好的交互性了。 參考文獻(xiàn) 1. Burbeck, S., Applications Programming in Smalltalk-80: How to use Model-View- Controller (MVC), 1987. 2. Cecchet, E., Chanda A., Elnikety S., Marguerite J., Zwaenepoel W.: Performance
27、 Comparison of Middleware Architectures for Generating Dynamic Web Content. Proceeding of the 4th International Middelware Conference, 2003. 3. Cecchet, E., Marguerite, J., and Zwaenepoel, W.: Performance and Scalability of EJB Applications. Proceedings of OOPSLA02, 2002. 4. Java Servlet and JavaSer
28、ver Pages Specification (JSR-053), aboutJava/communityprocess/final/jsr053/. 5. Java Servlet Specification (Proposed Final Draft 3), aboutJava/communityprocess/first/jsr154/. 6. JavaServer Faces Technology, JBoss EJB server, . 8. JMeter, JOnAS: Java Open Application Server, Sun Microsystems, Compari
29、ng Methods for Server-Side Dynamic Content, 2000. 11. The Apache Software Foundation, The Struts Framework, Wu, A., Wang, H., and Wilkins, D.: Performance Comparison of Alternative Solutions on Conference Southern the of Proceedings Applications. forWeb-To-Database Computing,the University of Southe
30、rn Mississippi, 2000. ?英文原文 A Comparative Study of Web Application Design Models Using the Java Technologies Budi Kurniawan and Jingling Xue School of Computer Science and Engineering University of New South Wales Sydney, NSW 2052, Australia Abstract. The Servlet technology has been the most widely
31、used technology for building scalable Web applications. In the events, there are four design models for developing Web applications using the Java technologies: Model 1, Model2, Struts, and JavaServer Faces (JSF). Model 1 employs a series of JSP pages; Model 2 adopts the Model-View-Controller patter
32、n; Struts is a framework employing the Model 2 design model; and JSF is a new technology that supports ready-to-use components for rapid Web application development. Model 1 is not recommended for medium-sized and large applications as it introduces maintenance nightmare. This paper compares and eva
33、luates the ease of application development and the performance of the three design models (Model 2, Struts, and JSF) by building three versions of an online store application using each of the three design models, respectively.1. Introduction Today, Web applications are the most common applications
34、for presenting dynamic contents. There are a number of technologies for building Web applications, the most popular of which is the Servlet technology . This technology gains its popularity from its superiority over other technologies such as CGI and PHP .Servlets are cumbersome to develop, however,
35、 because sending HTML tags requires the programmer to compose them into a String object and send this object to the browser. Also, a minor change to the output requires the servlet to be recompiled. To address this issue, Sun Microsystems invented JavaServer Pages (JSP) . JSP allows HTML tags to be
36、intertwined with Java code and each page is translated into a servlet. A JSP page is a servlet. However, compilation occurs automatically when the page is first requested. As a result, changing the output does not need recompilation. In addition, JSP enables the separation of presentation from the b
37、usiness logic through the use of JavaBeans and custom tag libraries. The norm now in developing Javabased Web applications is to use servlets along with JavaServer Pages. In the later development, there are a number of design models for building servlet/JSP applications: Model 1, Model 2, Struts , a
38、nd JSF . Model 1 and Model 2 were first mentioned in the early specifications of JSP. Model 1 strictly uses JSP pages, with no servlets, and Model 2 uses the combination of both servlets and JSP pages. The terms of Model 1 and Model 2 have been used ever since. Model 1 is suitable for prototypes and
39、 very small applications, and Model 2 is the recommended design model for medium sized and large applications. As Model 2 gained more acceptances in the industry, an open source initiative to build the Struts Framework was initiated. Struts perfects Model 2 by providing the controller part of the Mo
40、del-View-Controller of Model 2. In addition, Struts provides better page navigation management and several custom tag libraries for more rapid development. Despite its steep learning curve and the fact that it was never defined in any specification, Struts has been gaining popularity as the alternat
41、ive to Model 2.JavaServer Faces 6 is built under the Java Community Process under JSR-127. Sun Microsystems proposed this technology in the hope that JSF will be the ultimate model for building Java Web applications. The most important feature of JSF is the availability of ready-to-use components su
42、ch as extensible UI components, easy page navigation, input validators, data converters and JavaBeans management. The problem facing servlet/JSP programmers are to choose the most appropriate design model. Clearly, JSF provides a better solution in regard to development , some people are not sanguin
43、e to adopt this technology for fear of performance penalty due to the overhead of the JSF implementation. We build three versions of an online store application named BuyDirect using Model 2, Struts and JSF. The parameters compared are the number of lines of code,the number of classes, and the perfo
44、rmance measurement results. We investigate which of the design models allows the most rapid development process. We evaluate the performances of the applications built upon these models. We provide some suggestions to perfect the existing design models to make development more rapid. The rest of the
45、 paper is organised as follows. Section 2 discusses the issues in Web development. Section 3 explains how the three design models address these development issues. Section 4 provides the details of the hardware and software used in these experiments. Section 5 presents the experiment results and ana
46、lysis. Section 6 reviews the related work. Section 7 concludes by offering some suggestions to improve the existing design models. 2. Java Web Development Issues All Java Web development uses the Servlet technology as the underlying technology. As such, all Java Web applications have certain issues
47、that need to be addressed: ? User Interface. The user interface is what the client browser renders as HTML tags. Any server-side component used in the application must be encoded into the corresponding HTML elements. Besides for displaying the content and data, the user interface is also responsible
48、 in receiving input from the user. ? Input Validation. User input needs to be validated. There are two types of input validation, server-side and client-side. As the name implies, the server-side input validation is performed on the server after the input reaches the server. Client-side input valida
49、tion is done on the browser, usually by using JavaScript or other scripting languages. The advantages of using client-side input validation are prompt response and reducing the server workload. The server-side input validation should always be performed regardless the presence of client-side validat
50、ion because there is no guarantee the user browsers scripting feature is being on and malicious users can easily work around client-side validation. ? Model Objects. Model objects in Java-based Web applications are in the forms of JavaBeans. Model objects make up the Model part of the MVC based desi
51、gn model. A model object can be used to bind a component value to be used at a later stage. In addition, it can encapsulate business logic required for processing. ? Page Navigation. Almost all Web applications have multiple pages that the user can navigate from one to another. All MVC-based design
52、models use a servlet as the Controller part. This servlet also acts as the sole entry point to the application. Which page to be displayed after the current request is determined by the value of a specified request parameter. Managing page navigation is critically important. 3. Web Application Desig
53、n Models The Model 2 design model is based on the Model-View-Controller (MVC) design pattern. As explained by Burbeck 1, there are three main modules in MVC, the Controller, the View, and the Model. The Controller acts as the central entry point to the application. All user interactions go through t
54、his controller. The View contains the presentation part of the application, application. the of logic business encapsulates or data stores Model the and In the later development, the Struts Framework provides a common framework to easily build Model 2 applications. Then, the last initiative is the J
55、avaServer Faces, which also employs the MVC design pattern. In the following sections, we discuss these three design models and explain how each design model addresses the development issues specified in the previous section. 3.1 Model 2 A Java Web application that is based on the Model 2 design mod
56、el has one servlet (called the Controller servlet) that serves as the Controller part. All requests are first handled by this servlet, which immediately dispatches the requests to the appropriate views using RequestDispatcher objects. Views in the Model 2 design model are represented by JSP pages. T
57、o store data, a Model 2 application uses JavaBeans, which are the Model part of the application. In addition to storing data, the JavaBeans also encapsulate business logic. Each HTTP request carries an action parameter that indicates which view to dispatch this request to. The programmer must code the HTML tags for user interface in all JSP pages in the application and write input validation code. In addition, the model obj
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 股權(quán)轉(zhuǎn)讓及文化旅游產(chǎn)業(yè)融合發(fā)展協(xié)議
- 精神??谱o(hù)理門診規(guī)范化建設(shè)
- 蘇州變更離婚協(xié)議書
- 道路工程轉(zhuǎn)讓協(xié)議書
- 事故認(rèn)定書和解協(xié)議書
- 超市鞋架轉(zhuǎn)讓協(xié)議書
- 蘿卜書摘婚后協(xié)議書
- 邊貿(mào)生意轉(zhuǎn)讓協(xié)議書
- 項(xiàng)目自負(fù)盈虧協(xié)議書
- 公司給員工社保協(xié)議書
- 《更加注重價值創(chuàng)造能力 著力推進(jìn)國企高質(zhì)量發(fā)展》
- 關(guān)于我校中學(xué)生錯誤握筆姿勢調(diào)查及矯正的嘗試
- 積分制管理的實(shí)施方案及細(xì)則
- 正定古建筑-隆興寺
- 走進(jìn)物理-基礎(chǔ)物理智慧樹知到答案2024年廣西師范大學(xué)
- 三菱電梯型號縮寫簡稱
- 2024年版-生產(chǎn)作業(yè)指導(dǎo)書SOP模板
- 歷年考研英語一真題及答案
- 寵物殯葬師理論知識考試題庫50題
- 飛花令“水”的詩句100首含“水”字的詩句大全
- 門診常見眼科病
評論
0/150
提交評論