




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Struts一種開源MVC的實(shí)現(xiàn)這篇文章介紹Struts,一個(gè)使用servlet和 JavaServer Pages技術(shù)的一種 Model-View-Controller 的實(shí)現(xiàn)。 Struts 可以幫助你控制 Web 項(xiàng)目中的變化并提高專業(yè)化。即使你可能永遠(yuǎn)不會(huì)用 Struts 實(shí)現(xiàn)一個(gè)系統(tǒng),你可以獲得一些想法用于你未來的servlet和 JSP 網(wǎng)頁的實(shí)現(xiàn)中。簡介在小學(xué)校園里的小孩子們都可以在因特網(wǎng)上發(fā)布HTML 網(wǎng)頁。然而,有一個(gè)重大的不同在一個(gè)小學(xué)生和一個(gè)專業(yè)人士開發(fā)的網(wǎng)站之間。網(wǎng)頁設(shè)計(jì)師(或者HTML開發(fā)人員)必須理解顏色、用戶、生產(chǎn)流程、網(wǎng)頁布局、瀏覽器兼容性、圖像創(chuàng)建、JavaS
2、cript等等。設(shè)計(jì)漂亮的網(wǎng)站需要做大量的工作,大多數(shù)Java開發(fā)人員更注重創(chuàng)建優(yōu)美的對象接口,而不是用戶界面。JavaServer Pages (JSP)技術(shù)為網(wǎng)頁設(shè)計(jì)人員和 Java開發(fā)人員提供了一種聯(lián)系鈕帶。如果你開發(fā)過大型Web 應(yīng)用程序,你就理解“變化”這個(gè)詞語。 “模型 - 視圖 -控制器” (MVC) 就是用來幫助你控制變化的一種設(shè)計(jì)模式。MVC減弱了業(yè)務(wù)邏輯接口和數(shù)據(jù)接口之間的耦合。Struts是一種 MVC 實(shí)現(xiàn),它將 Servlet 2.2和 JSP1.1標(biāo)記(屬于 J2EE 規(guī)范)用作實(shí)現(xiàn)的一部分。你可能永遠(yuǎn)不會(huì)用Struts實(shí)現(xiàn)一個(gè)系統(tǒng),但了解一下Struts或許使你能
3、將其中的一些思想用于你以后的Servlet和 JSP 實(shí)現(xiàn)中。模型 - 視圖 - 控制器 (MVC)JSP標(biāo)簽只解決了我們問題中的一部分。我們依然有驗(yàn)證、流控制、以及更新應(yīng)用程序結(jié)構(gòu)的問題。這就是MVC從哪兒來以及來干嘛的。MVC通過把問題分成三類來幫助解決一些與單模塊相關(guān)的問題:? Model(模型)模塊包括應(yīng)用程序功能的核心。模型封裝著應(yīng)用程序的各個(gè)結(jié)構(gòu)。有時(shí)它所包含的唯一功能就是結(jié)構(gòu)。它對于視圖或者控制器一無所知。? View(視圖)視圖提供了模型的演示。它是應(yīng)用程序的外表。視圖可以進(jìn)入模型獲得者,.但是它對于設(shè)置者一無所知。除此之外,它對于控制器也是一無所知。視圖僅僅當(dāng)模型發(fā)生改變的時(shí)
4、候才被通知。? Controller (控制器)控制器對于用戶的輸入做出反應(yīng)。它創(chuàng)造和設(shè)置模型。MVC模型 2Web 給軟件開發(fā)人員帶來了一些獨(dú)特的挑戰(zhàn),最顯著的就是客戶端和服務(wù)器端的無結(jié)構(gòu)連接。這種無結(jié)構(gòu)連接行為使得模型很難知道視圖的改變。在Web上,瀏覽器必須重復(fù)詢問服務(wù)器端以此來發(fā)現(xiàn)應(yīng)用程序結(jié)構(gòu)的改變。另外一個(gè)顯而易見的改變就是相對于模型或者控制器,視圖采用了不同的技術(shù)。當(dāng)然,我們可以使用Java (或者 PERL、C/C+ 或之前的其他代碼)代碼來生成 HTML。這種方法存在一些弊端:?Java 程序員應(yīng)該開發(fā)服務(wù),而不是HTML。布局的改變將需要改變代碼。服務(wù)的客戶將有能力去創(chuàng)造一些
5、頁面去滿足他們的一些特殊需求。頁面設(shè)計(jì)人員將不能直接介入到頁面的開發(fā)中。嵌入在代碼中的HTML將會(huì)變得丑陋。對于 Web,MVC的經(jīng)典形式將需要改變。圖4 展示了 MVC的 Web適應(yīng),也就是通常所說的 MVC模型 2 或者 MVC 2。 .圖4.MVC模型2Struts ,MVC 2 的一種實(shí)現(xiàn)Struts 是一組相互協(xié)作的類、 servlet 和 JSP 標(biāo)記,它們組成一個(gè)可重用的 MVC 2 設(shè)計(jì)。這個(gè)定義表示 Struts 是一個(gè)框架,而不是一個(gè)庫,但 Struts 也包.含了豐富的標(biāo)記庫和獨(dú)立于該框架工作的實(shí)用程序類。圖5顯示了 Struts的一個(gè)概覽。圖 5. Struts概覽St
6、ruts概覽? 客戶端瀏覽器一個(gè)來自客戶端瀏覽器的HTTP創(chuàng)建一個(gè)事件。Web 容器將會(huì)用一個(gè)HTTP 響應(yīng)來作出響應(yīng)。? 控制器控制器接收來自瀏覽器的請求,并決定發(fā)送請求到何處。就Struts而言,控制器就是一個(gè)以servlet執(zhí)行的一個(gè)命令設(shè)計(jì)模式。struts-config.xml文件配置控制器。? 業(yè)務(wù)邏輯業(yè)務(wù)邏輯更新模型的狀態(tài),并幫助控制應(yīng)用程序的流。就Struts而言,這就是通過作為實(shí)際業(yè)務(wù)邏輯“瘦”包裝的Action類完成的。? 模型狀態(tài)模型代表了應(yīng)用程序的狀態(tài)。業(yè)務(wù)對象更新應(yīng)用程序的狀態(tài)。ActionFormbean 在會(huì)話級或請求級表示模型的狀態(tài),而不是在持久級。JSP 文件
7、使用JSP 標(biāo)記讀取來自 ActionForm bean的信息。?視圖視圖就是一個(gè) JSP 文件。其中沒有流程邏輯,沒有業(yè)務(wù)邏輯,也沒有模型信息 -只有標(biāo)記。標(biāo)記是使Struts有別于其他框架(如Velocity)的因素之一。.Struts 詳細(xì)資料在圖 6 中展示了一個(gè)無其他附屬設(shè)備的阿帕奇 struts 的 action 包的 UML圖表。圖 6顯示了 ActionServlet(Controller) 、ActionForm (Form State) 和 Action(Model Wrapper)之間的最小關(guān)系。圖 6.命令 (ActionServlet)與 模型 (Action&
8、; ActionForm)之間的關(guān)系的UML圖ActionServlet類你還記得使用函數(shù)映射的日子嗎?你會(huì)映射一些輸入時(shí)間到一個(gè)函數(shù)的一個(gè)指針。如果你很老練,你可以把這些配置信息放進(jìn)一個(gè)文件里并且在運(yùn)行時(shí)加載該文件。函數(shù)指針裝扮了在C語言結(jié)構(gòu)化程序設(shè)計(jì)中的舊時(shí)光?,F(xiàn)在日子好過多了,自從我們有了Java 技術(shù)、 XML、 J2EE等等之后。 Struts控制器是一個(gè)映射事件(事件通常是一個(gè)HTTP post )到類的一個(gè) servlet。猜猜怎么著 -控制器用一個(gè)配置文件以致于你不必非硬編碼這些值。生活變了,但方法依然如此。ActionServlet是 MVC 實(shí)現(xiàn)的命令部分并且它是框架的核心
9、。ActionServlet (Command)創(chuàng)建并使用 Action、 ActionForm和ActionForward。正如前面所提及的,struts-config.xml文件配置 Command。在Web 工程創(chuàng)建期間,Action和 ActionForm被擴(kuò)展用來解決特殊的問題空間。文件 struts-config.xml指導(dǎo) ActionServlet如何擴(kuò)展這些類。這種方法有幾個(gè)優(yōu)點(diǎn):?網(wǎng)頁設(shè)計(jì)人員不必費(fèi)力地通過Java 代碼來理解應(yīng)用程序的流程。當(dāng)流程發(fā)生改變時(shí)Java 開發(fā)人員不需要重新編譯代碼。.? 通過擴(kuò)展 ActionServlet 命令函數(shù)可以被添加進(jìn)來。Action
10、Form類ActionForm維持著 Web應(yīng)用程序的會(huì)話狀態(tài)。ActionForm是一個(gè)必須為每個(gè)輸入表單模型創(chuàng)建該類的子類的抽象類。當(dāng)我說輸入表單模型時(shí), 我就是說ActionForm代表了一個(gè)由 HTML 表單設(shè)置或更新的一般意義上的數(shù)據(jù)。例如,你可能有一個(gè)由 HTML 表單設(shè)置的 UserActionForm。Struts框架將會(huì):? 檢查 UserActionForm 是否存在;如果不存在,它將會(huì)創(chuàng)建該類的一個(gè)實(shí)例。? Struts 將使用 HttpServletRequest中相應(yīng)的域設(shè)置UserActionForm 的狀態(tài)。沒有太多糟糕的請求 .getParameter() 調(diào)用
11、。例如, Struts 框架將從請求流中提取 fname 并調(diào)用UserActionForm.setFname()。? Struts 框架在將在傳遞它到業(yè)務(wù)包裝 UserAction 之前將更新UserActionForm 的狀態(tài)。?在傳遞它到 Action類之前, Struts將還會(huì)對 UserActionForm調(diào)用 validation() 方法進(jìn)行表單驗(yàn)證。 備注: 這樣做通常并不明智。別的網(wǎng)頁或業(yè)務(wù)對象可能有方法使用 UserActionForm ,然而驗(yàn)證可能不同。在 UserAction 類中進(jìn)行狀態(tài)驗(yàn)證可能更好。? UserActionForm 能夠維持一個(gè)會(huì)話級別 。備注:?
12、 struts-config.xml文件控制著 HTML 表單請求與 ActionForm之間的映射。?多重請求會(huì)被映射到UserActionForm。UserActionForm可被映射到諸如向?qū)е惖亩嘀仨撁娴臇|西上。Action類Action 類是一個(gè)圍繞業(yè)務(wù)邏輯的一個(gè)包裝器。 Action 類的目的就是將 HttpServletRequest 翻譯給業(yè)務(wù)邏輯。 要使用 Action ,需重寫 process() 原理。.ActionServlet (命令 ) 通過使用 perform()原理將參數(shù)化的類傳遞給ActionForm。此外,沒有太多討厭的request.getParamet
13、er()調(diào)用。通過事件到達(dá)這里的時(shí)間,輸入表單數(shù)據(jù)(或HTML 表單數(shù)據(jù))已經(jīng)被從請求流中翻譯出來并進(jìn)入 ActionForm類中。注:擴(kuò)展 Action類時(shí)請注意簡潔。Action類應(yīng)該控制應(yīng)用程序的流程,而不應(yīng)該控制應(yīng)用程序的邏輯。通過將業(yè)務(wù)邏輯放在單獨(dú)的包或EJB 中,我們就可以提供更大的靈活性和可重用性??紤] Action類的另一種方式是Adapter設(shè)計(jì)模式。 Action的用途是“將類的接口轉(zhuǎn)換為客戶機(jī)所需的另一個(gè)接口。Adapter使類能夠協(xié)同工作,如果沒有Adapter ,則這些類會(huì)因?yàn)椴患嫒莸慕涌诙鵁o法協(xié)同工作?!保ㄕ訥of 所著的Design Patterns - Ele
14、ments of Reusable OO Software)。本例中的客戶機(jī)是ActionServlet,它對我們的具體業(yè)務(wù)類接口一無所知。因此,Struts 提供了它能夠理解的一個(gè)業(yè)務(wù)接口,即Action。通過擴(kuò)展 Action,我們使得我們的業(yè)務(wù)接口與 Struts業(yè)務(wù)接口保持兼容。(一個(gè)有趣的發(fā)現(xiàn)是,Action是類而不是接口)。 Action開始為一個(gè)接口,后來卻變成了一個(gè)類。真是金無足赤。 )Error 類UML圖(圖 6 )還包括 ActionError和 ActionErrors。 ActionError 封裝了單個(gè)錯(cuò)誤消息。 ActionErrors是 ActionError類
15、的容器, View 可以使用標(biāo)記訪問這些類。 ActionError是 Struts保持錯(cuò)誤列表的方式。圖 7. Command (ActionServlet)與 Model (Action)之間的關(guān)系的 UML 圖ActionMapping類.輸入事件通常是在HTTP 請求表單中發(fā)生的, servlet容器將 HTTP 請求轉(zhuǎn)換為 HttpServletRequest??刂破鞑榭摧斎胧录⒄埱蠓峙山o某個(gè)Action類。struts-config.xml確定 Controller調(diào)用哪個(gè) Action類。 struts-config.xml配置信息被轉(zhuǎn)換為一組ActionMapping,而后
16、者又被放入ActionMappings容器中。(你可能尚未注意到這一點(diǎn),以s 結(jié)尾的類就是容器)ActionMapping包含有關(guān)特定事件如何映射到特定Action的信息。ActionServlet (Command)通過 perform()方法將 ActionMapping傳遞給Action類。這樣就使 Action可訪問用于控制流程的信息。ActionMappingsActionMappings是 ActionMapping對象的一個(gè)集合。Struts的優(yōu)點(diǎn)? JSP 標(biāo)記機(jī)制的使用標(biāo)記特性從 JSP 文件獲得可重用代碼和抽象Java代碼。這個(gè)特性能很好地集成到基于 JSP 的開發(fā)工具中,
17、這些工具允許用標(biāo)記編寫代碼。? 標(biāo)記庫為什么要另發(fā)明一種輪子,或標(biāo)記庫呢?如果你在庫中找不到你所要的標(biāo)記,那就自己定義吧。 此外,如果你正在學(xué)習(xí)JSP 標(biāo)記技術(shù),則 Struts為你提供了一個(gè)起點(diǎn)。? 開放源碼你可以獲得開放源碼的全部優(yōu)點(diǎn),比如可以查看代碼并讓使用庫的每個(gè)人檢查代碼。許多人都可以進(jìn)行很好的代碼檢查。? MVC實(shí)現(xiàn)樣例如果你希望創(chuàng)建你自己的MVC 實(shí)現(xiàn),則 Struts可增加你的見識。? 管理問題空間分治是解決問題并使問題可管理的極好方法。當(dāng)然,這是一把雙刃劍。問題越來越復(fù)雜,并且需要越來越多的管理。Struts的缺點(diǎn).? 仍處于發(fā)展初期Struts開發(fā)仍處于初級階段。他們正在向
18、著發(fā)行版本1.0而努力,但與任何 1.0版本一樣,它不可能盡善盡美。? 仍在變化中這個(gè)框架仍在快速變化。Struts 1.0與 Struts 0.5相比變化極大。為了避免使用不贊成使用的方法,你可能隔一天就需要下載最新的Struts。在過去的 6個(gè)月中,我目睹Struts庫從 90K 增大到 270K 以上。由于Struts中的變化,我不得不數(shù)次修改我的示例,但我不保證我的示例能與你下載的 Struts協(xié)同工作。? 正確的抽象級別Struts是否提供了正確的抽象級別?對于網(wǎng)頁設(shè)計(jì)人員而言,什么是正確的抽象級別呢?這是一個(gè)用$64K 的文字才能解釋清楚的問題。在開發(fā)網(wǎng)頁的過程中,我們是否應(yīng)該讓網(wǎng)
19、頁設(shè)計(jì)人員訪問Java代碼?某些框架(如Velocity)說不應(yīng)該,但它提供了另一種Web 開發(fā)語言讓我們學(xué)習(xí)。在UI開發(fā)中限制訪問Java有一定的合理性。最重要的是,如果讓網(wǎng)頁設(shè)計(jì)人員使用一點(diǎn) Java ,他將使用大量的Java 。在 Microsoft ASP的開發(fā)中,我總是看到這樣的情況。在 ASP 開發(fā)中,你應(yīng)該創(chuàng)建 COM 對象,然后編寫少量的 ASP 腳本將這些 COM 對象聯(lián)系起來。但是, ASP 開發(fā)人員會(huì)瘋狂地使用 ASP 腳本。我會(huì)聽到這樣的話, “既然我可以用 VBScript 直接編寫 COM 對象,為什么還要等 COM 開發(fā)人員來創(chuàng)建它呢?”通過使用標(biāo)記庫, Stru
20、ts 有助于限制 JSP 文件中所需的 Java 代碼的數(shù)量。 Logic Tag 就是這樣的一種庫,它對有條件地生成輸出進(jìn)行管理,但這并不能阻止UI開發(fā)人員對Java 代碼的狂熱。無論你決定使用哪種類型的框架,你都應(yīng)該了解你要在其中部署和維護(hù)該框架的環(huán)境。當(dāng)然,這項(xiàng)任務(wù)真是說起來容易做起來難。? 有限的適用范圍Struts是一種基于 Web 的 MVC 解決方案,所以必須用HTML、JSP 文件和servlet來實(shí)現(xiàn)它。?J2EE 應(yīng)用程序支持Struts需要支持 JSP 1.1和 Servlet 2.2規(guī)范的 servlet容器。僅憑這一點(diǎn)遠(yuǎn)不能解決你的全部安裝問題,除非使用Tomcat
21、3.2 。我用 Netscape.iPlanet 6.0安裝這個(gè)庫時(shí)遇到一大堆問題,按理說它是第一種符合J2EE的應(yīng)用程序服務(wù)器。我建議你在遇到問題時(shí)訪問Struts用戶郵件列表的歸檔資料。? 復(fù)雜性在將問題分為幾個(gè)部分的同時(shí)也引入了復(fù)雜性。毫無疑問,要理解Struts必須接受一定的培訓(xùn)。隨著變化的不斷加入,這有時(shí)會(huì)令人很沮喪。歡迎訪問本網(wǎng)站。Struts的前景在軟件開發(fā)的新時(shí)代事物都變化得很快。在最近5 年里,我目睹過事物從cgi/perl ,再到 ISAPI/NSAPI 、再到使用 VB 的 ASP、一直到現(xiàn)在的 Java 和 J2EE 的變遷。 Sun 正在努力地適應(yīng) JSP/servl
22、et 結(jié)構(gòu),就像他們通過 Java 語言和 API 在過去。你可以從 Sun 的網(wǎng)站獲得新的 JSP 1.2 和 Servlet 2.3 規(guī)范的草案。此外,一個(gè)標(biāo)準(zhǔn)的JSP 標(biāo)記庫正在出現(xiàn)。.附件 2:外文原文 (復(fù)印件)出自 IBM System Journal,2006,44(2):33-37作者: Malcolm DavisStruts An Open-source MVC ImplementationThis article introduces Struts, a Model-View-Controller implementation that usesservletsand Ja
23、vaServerPages (JSP) technology.Strutscan help you controlchange inyourWeb projectand promotespecialization.Even ifyou neverimplementa system withStruts, you may get some ideas for your future servlets and JSP page implementationIntroductionKidsingradeschoolput HTMLpages on the Internet.However, ther
24、eisa monumentaldifference between a grade school page and a professionally developed Web site. Thepage designer(orHTMLdeveloper)must understandcolors,thecustomer,productflow,page layout, browser compatibility, image creation, JavaScript, and more. Putting agreat looking site together takes a lot of
25、work, and most Java developers are moreinterestedincreatingagreatlookingobjectinterfacethan auserinterface.JavaServerPages (JSP)technologyprovidesthe gluebetween the page designerand theJava developer.Ifyou have worked on a large-scaleWebapplication,you understandtheterm change.Model-View-Controller
26、 (MVC) is a design pattern put together to help control change.MVCdecouplesinterfacefrom businesslogicand data.Strutsis an MVCimplementationthat uses Servlets 2.2 and JSP 1.1 tags, from the J2EE specifications, as part of theimplementation. You may never implement a system with Struts, but looking a
27、t Strutsmay give you some ideas on your future Servlets and JSP implementations.Model-View-Controller (MVC)JSP tagssolved onlypartofour problem.We stillhave issues withvalidation,flowcontrol,and updating the stateoftheapplication.Thisiswhere MVCcomes totherescue.MVC helps resolve some of the issues
28、with the single module approach by dividing the problem into three categories:? ModelThe model contains the core of the application's functionality. The modelencapsulates the state of the application. Sometimes the only functionality it contains is state. It knows nothing about the view or contr
29、oller.?ViewThe view providesthe presentationof the model. Itis the look of the application.The view can access the model getters, but it has no knowledge of the setters.Inaddition,itknows nothingaboutthe controller.The view shouldbe notifiedwhen changes to the model occur.?ControllerThe controller r
30、eacts to the user input. It creates and sets the model.MVC Model 2.?The Web brought some unique challenges to software developers, most notably the stateless connection between the client and the server. This stateless behaviormade it difficult for the model to notify the view of changes. On the Web
31、, thebrowserhas to re-querythe servertodiscovermodificationto the stateof theapplication.? Another noticeable change is that the view uses different technology for implementation than the model or controller. Of course, we could use Java (orPERL, C/C+ or what ever) code to generate HTML. There are s
32、everal disadvantages to that approach:? Java programmers should develop services, not HTML.? Changes to layout would require changes to code.? Customers of the service should be able to create pages to meet their specific needs.? The page designer isn't able to have direct involvement in page de
33、velopment.? HTML embedded into code is ugly.? For the Web, the classical form of MVC needed to change. Figure 4 displays the Web adaptation of MVC, also commonly known as MVC Model 2 or MVC 2.?Struts details?Figure 6. UML diagram of the relationship of the Command (ActionServlet)to the Model (Action
34、 & ActionForm)The ActionServlet classDo you remember the days of functionmappings? You would map some inputevent to a pointer.to a function. If you where slick,you would place theconfiguration information intoa file and load the file at run time. Function pointer arrays were the good old days of
35、 structured programming in C.? Life is better now that we have Java technology, XML, J2EE, and all that. The Struts Controller is a servlet that maps events (an event generally being anHTTP post) to classes. And guess what - the Controller uses a configurationfileso you don_t have to hard-codethe va
36、lues.Lifechanges,but staysthe same.? ActionServlet is the Command part of the MVC implementation and is the core ofthe Framework. ActionServlet(Command) createsand uses Action,an ActionForm,and ActionForward.As mentionedearlier,the struts-config.xmlfileconfiguresthe Command. During thecreationof the
37、Web project,Action andActionForm areextended to solve the specific problem space. The file struts-config.xmlinstructs ActionServlet on how to use the extended classes. There are severaladvantages to this approach:?The entire logicalflowofthe applicationisina hierarchicaltextfile.Thismakes it easier
38、to view and understand, especially with large applications.?The page designerdoes nothave to wade throughJava code to understand theflowof the application.? The Java developer does not need to recompile code when making flow changes.? Command functionality can be added by extending ActionServlet.The
39、 ActionForm class? ActionForm maintains the session state for the Web application. ActionForm isan abstract class that is sub-classed for each input form model. WhenI say input form model, I am saying ActionForm represents a general concept of data thatis set or updated by a HTML form. For instance,
40、 you may have a UserActionForm that is set by an HTML Form. The Struts framework will:? Check to see if a UserActionForm exists; if not, it will create an instance of the class.?Strutswillset the stateof the UserActionFormusing correspondingfieldsfromthe HttpServletRequest. No more dreadful request.
41、getParameter() calls. Forinstance, the Struts framework will take fname from request stream and call UserActionForm.setFname().?The Strutsframeworkupdatesthe stateof the UserActionFormbeforepassingitto the business wrapper UserAction.? Before passing it to the Action class, Struts will also conduct
42、form statevalidationby callingthe validation()method on UserActionForm.Note: Thisisnot always wise to do.There might be ways of using UserActionFormin otherpagesor businessobjects,where the validationmight be different.Validationofthestate might be better in the UserAction class.? The UserActionForm
43、 can be maintained at a session level.? Notes:.? The struts-config.xml file controls which HTML form request maps to which ActionForm.? Multiple requests can be mapped UserActionForm.? UserActionForm can be mapped over multiple pages for things such as wizards.The Action classThe Actionclassisa wrap
44、per around the businesslogic.The purposeof Actionclassisto translatethe HttpServletRequestto the businesslogic.To use Action,subclassand overwrite the process() method.The ActionServlet (Command) passes the parameterized classes to ActionForm using the perform() method. Again, no more dreadful reque
45、st.getParameter() calls. By the timethe event gets here, the input form data (or HTMLform data) has already been translated out of the request stream and into an ActionForm class.Figure 4. MVC Model 2Struts, an MVC 2 implementationStruts is a set of cooperating classes, servlets, and JSP tags MVC2 d
46、esign. This definition implies that Struts is a framework,but Struts also contains an extensive tag library and utility classes that work independently of the framework. Figure 5 displays an overview of Struts.that make up a reusable rather than a library,.Figure 5. Struts overviewStruts overview? C
47、lient browserAn HTTP request from the client browser creates an event. The Webcontainer will respond with an HTTP response.? ControllerThe Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the Controller is a command design pattern imple
48、mented as a servlet. The struts-config.xml file configures the Controller.? Business logicThe business logic updates the state of the model and helps control the flow of the application. With Struts this is done with an Action class as a thin wrapper to the actual business logic.? Model stateThe mod
49、el representsthe stateof the application.The businessobjectsupdatethe application state. ActionForm bean represents the Model state at a session or request level, and not at a persistent level. The JSP file reads information from the ActionForm bean using JSP tags.? ViewThe view is simply a JSP file. There is no flow logic, no business logic, and no model information - just tags. Tags are one of the things that make Struts unique compared to other fram
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 第一單元-四則運(yùn)算(培優(yōu)卷)-小學(xué)數(shù)學(xué)四年級下冊高頻易錯(cuò)題真題專項(xiàng)突破(人教版-含答案)
- 南京2024年江蘇南京大學(xué)前沿科學(xué)學(xué)院專用先進(jìn)技術(shù)準(zhǔn)聘長聘教師崗位招聘筆試歷年參考題庫附帶答案詳解
- 疼痛對患者家庭關(guān)系的影響及心理干預(yù)策略
- 社交媒體下的網(wǎng)絡(luò)安全問題及策略
- 科技行業(yè)人才需求與培養(yǎng)策略的匯報(bào)制作
- 生產(chǎn)線員工KPI設(shè)定與考核要點(diǎn)解析
- 混合變現(xiàn)模式網(wǎng)絡(luò)社交平臺的多元盈利路徑探索
- 科技行業(yè)職場心理壓力解析
- 科技發(fā)展與外語導(dǎo)游詞翻譯的融合
- 社會(huì)責(zé)任與可持續(xù)發(fā)展戰(zhàn)略
- 2024年南京旅游職業(yè)學(xué)院高職單招語文歷年參考題庫含答案解析
- 《電商直播》 課件 項(xiàng)目一 走入電商直播
- 豐田卡羅拉電路圖介紹
- 中考語文十大專題總復(fù)習(xí)資料
- 汽車駕駛員專業(yè)競賽實(shí)施方案
- 知乎的SWOT分析(表格)
- 常用家電維修基礎(chǔ)知識(課堂PPT)
- 楊氏太極拳37式拳譜
- 臥式設(shè)備安裝
- 橋梁施工危險(xiǎn)源辨識與防控措施
- CFG樁施工記錄表范本
評論
0/150
提交評論