2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、<p><b>  譯 文</b></p><p>  Apache Struts 2</p><p>  “Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is

2、designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time” -The Apache Software Foundation.</p><p><b>  4.1簡介</b></p><p> 

3、 Struts是Apache的一個(gè)應(yīng)用于Java Web的網(wǎng)絡(luò)編程的開源框架。Struts框架的創(chuàng)造者和發(fā)起者是McClanahan。后來在2002年,Struts框架由Apache軟件基金會(huì)收購和接管。Struts提供給程序員一個(gè)易于組織基于JSP和Servlet的HTML格式和Java代碼的框架。Struts1幾乎能與所有標(biāo)準(zhǔn)的Java技術(shù)和Jakarta配置包協(xié)同工作。然而,隨著需求的不斷增長,Struts1在網(wǎng)絡(luò)應(yīng)用程序暴露出來

4、許多問題,所以為了滿足需求,導(dǎo)致Strut2推出,Strut2能更好地為開發(fā)者提供服務(wù),如 Ajax、高效開發(fā)和可擴(kuò)展性。</p><p>  4.1.1 Struts 2的起源</p><p>  自從2000年Apache Struts的發(fā)起,Struts框架取得了非常大的成功,被大多數(shù)標(biāo)準(zhǔn)所接納,得到了很大的發(fā)展,如果不是這樣,哪里會(huì)有今天java web程序的成績。它的歷史,告訴我

5、們Struts是怎樣組織JSP和/ Servlets,而提供了固定的框架。Struts融入server-generated HTML與Javascript,客戶端驗(yàn)證,也使得開發(fā)比較容易和維護(hù)。隨著時(shí)間推進(jìn)的和客戶對web需求擴(kuò)大,網(wǎng)站應(yīng)用程序取得碩果累累,Struts1太老了,開始在越來越多的網(wǎng)站前端開發(fā)者視野中淡去。</p><p>  在2005年的java技術(shù)大會(huì)上,許多的truts開發(fā)者探討Struts

6、未來的出路和建議。他們想要設(shè)想一個(gè)框架,要求它能聚集了許多網(wǎng)絡(luò)編程的優(yōu)點(diǎn)。問題是Struts1代碼對ServletAPI依賴,不宜于擴(kuò)展,特別是缺乏豐富的視圖表現(xiàn)特征如Ajax、高效開發(fā)和擴(kuò)展性。與此同時(shí),他們也和其他開發(fā)商如the Spring WebFlow,探討幾個(gè)框架統(tǒng)一到一個(gè)框架中。然而,有一些關(guān)項(xiàng)目所有權(quán)、品牌、和身份的問題阻礙了進(jìn)程。幸運(yùn)的是,開發(fā)者在 Struts and WebWor兩個(gè)框架中看到了“合并”的可能性。&

7、lt;/p><p>  在當(dāng)時(shí),Struts的開發(fā)者也正在研發(fā)Shale框架,由于Shale是Struts的子項(xiàng)目,沿著Struts Action 1(現(xiàn)在叫Struts 1)方向,Struts Action 2(源于WebWork2)。不幸是,在當(dāng)時(shí)這些框架類別非?;靵y的。人們習(xí)慣了“Struts”這個(gè)名字。在融入Struts Action 2和Shale 成Struts 2時(shí), Shale的開發(fā)者覺得如果在原有的

8、基礎(chǔ)上發(fā)展那樣會(huì)更好。于Struts Action 2 很快就被重新命名為Struts2。</p><p>  今天,Apache Struts有兩個(gè)版本的框架,但它們都是基于Action相應(yīng)的框架。 Struts 2的設(shè)計(jì)思想和核心來自于WebWork。Struts 2從最初版本,它具有插件框架,新的API,更好地支持 Ajax標(biāo)簽。Struts 2在不斷發(fā)展中。</p><p>  4

9、.2 Struts 2 特點(diǎn)</p><p>  4.2.1 MVC 架構(gòu)</p><p>  Struts 2繼承Struts1優(yōu)良特點(diǎn),也是用于開發(fā)web應(yīng)用程序的一個(gè)開放源碼的J2EE框架,使用模型、視圖、控制器的設(shè)計(jì)模式。MVC的主要是分離與應(yīng)用數(shù)據(jù)的業(yè)務(wù)邏輯與表現(xiàn)的數(shù)據(jù)。這也是是使用MVC設(shè)計(jì)模式的原因。</p><p>  可重用性:當(dāng)遇到一類問題的出現(xiàn)

10、,不需要再創(chuàng)建一個(gè)新的解決方案,只是要遵循的模式。</p><p>  易于理解:采用MVC設(shè)計(jì)模式,讓應(yīng)用程序變得更加可讀和理解的。</p><p>  4.2.1.1 模型</p><p>  總所周知,模型層負(fù)責(zé)表現(xiàn)所有的業(yè)務(wù)數(shù)據(jù)。模型關(guān)心的是應(yīng)用的請求處理,模型是專門負(fù)責(zé)維護(hù)數(shù)據(jù)的,它負(fù)責(zé)業(yè)務(wù)數(shù)據(jù)按照業(yè)務(wù)規(guī)則進(jìn)行執(zhí)行對數(shù)據(jù)的訪問和更新操作,模型并不關(guān)心持久化

11、數(shù)據(jù)操作和數(shù)據(jù)是如何在用戶端展現(xiàn)的。</p><p>  4.2.1.2 視圖</p><p>  視圖表達(dá)用戶所提交的請求。視圖依賴于模型。視圖調(diào)用模型提供的取值方法查詢業(yè)務(wù)狀態(tài),但是它本身并不依賴于應(yīng)用的程序的邏輯。視圖層時(shí)刻保持與業(yè)務(wù)邏輯相對應(yīng)的一致性。換句話說,我們可以說它的任務(wù)是一旦模式層變化視圖也跟著變化調(diào)整,而達(dá)到與模式層保持一致性。</p><p>

12、  4.2.1.3 控制器</p><p>  用戶每發(fā)送一個(gè)請求總是要經(jīng)過控制器??刂破魇秦?fù)責(zé)監(jiān)聽和接收用戶請求,并且通過它傳遞給模型,模型做適當(dāng)?shù)奶幚?。?shù)據(jù)處理完成后,控制器負(fù)責(zé)選擇合適的視圖展現(xiàn)給用戶。在GUIs應(yīng)用程序里,視圖層和控制器通常是緊密協(xié)調(diào)工作的。</p><p>  4.2.2 Struts 2是如何完美運(yùn)用MVC模式呢</p><p>  Th

13、e Struts 2的控制器 </p><p>  每當(dāng)用戶發(fā)來請求時(shí),請求都要被FilterDispatcher處理。當(dāng)FilterDispatcher接收該請求,它會(huì)根據(jù)配置文件截獲URL,然后將請求處理給Action類。Action類是另外一個(gè)控制器, Action負(fù)責(zé)與模式層會(huì)話。</p><p>  The Struts 2 的視圖</p><p>  視

14、圖負(fù)責(zé)展現(xiàn)信息給用戶與接受用戶的輸入。我們大多使用JSP作為視圖展現(xiàn)。,Struts提供給我們豐富的視圖,如自定義用戶標(biāo)簽、java腳本等。</p><p>  The Struts 2 的模型層</p><p>  模型層表示Struts 2應(yīng)用程序業(yè)務(wù)邏輯。模型層提供訪問數(shù)據(jù)庫的接口或者一些對外接口。模型層通常是一些java類,里面沒有定義針對具體的模型,而是抽象的,這樣提搞了代碼的重

15、用性。</p><p>  4.2.3 Struts 2 帶來什么</p><p>  Struts 2集Struts 和Web Work2兩大框架于一體,通過使用Web Work2及集成一些插件框架,一些新的API,AJAX標(biāo)記等,因此Struts 2是動(dòng)態(tài)、易擴(kuò)展框架,對于復(fù)雜大型工程,Struts 2能出色的完成從開發(fā)、部署到維護(hù)。Struts 2是面向接口編程的,易于擴(kuò)展。配置基本

16、要求Servlet API 2.4,JSP API 2.0 ,Java 5 以上。</p><p>  Struts 2框架特點(diǎn):</p><p>  Architecture:首先,F(xiàn)ilterDispatcher攔截Web瀏覽器發(fā)來的請求和決定調(diào)用Action類;其次,在Action類execute()方法執(zhí)行前后如存儲數(shù)據(jù)和查詢數(shù)據(jù),大量的攔截器將被調(diào)用。最后,處理結(jié)果將以HTML、

17、PDF、圖片等形式返回輸出到瀏覽器。</p><p>  Tags:Struts 2引用標(biāo)記,減少了web程序代碼量。Struts 2中的標(biāo)記既包括輸出數(shù)據(jù),也有樣式表。這些標(biāo)簽也具有驗(yàn)證和序列化功能。使用標(biāo)簽的web程序代碼,提高程序的可讀性和維護(hù)性。</p><p>  MVC:Struts 2中MVC起到協(xié)調(diào)者作用。Struts 2有自己的庫和標(biāo)記標(biāo)簽。Configuration:S

18、truts 2提供了一種以XML格式的部署描述符來初始化資源。初始化工作僅僅通過掃描所有Java包或者使用一個(gè)應(yīng)用程序配置文件來控制整個(gè)配置。配置文件的重新加載可以不用重啟web容器。</p><p>  Struts 2框架其他特點(diǎn):</p><p>  所有類都是基于接口及核心接口編程,是相對獨(dú)立于HTTP。</p><p>  任何類可作為一個(gè)Action類,

19、可以JavaBean輸入屬性,直接關(guān)聯(lián)到Action類方法。</p><p>  Struts 2易于與Spring框架集成。</p><p>  AJAX使得應(yīng)用程序更加靈活。</p><p>  4.2.4 深入Struts 2 框架</p><p>  集Struts和Webwork兩大框架一體的Struts2,開發(fā)出來的Web應(yīng)用程序

20、是可擴(kuò)展的、優(yōu)秀的。本節(jié)我們將討論Struts2框架。</p><p>  首先,看看Struts2工作流程:</p><p>  用戶請求:用戶發(fā)送請求給服務(wù)器,請求資源。</p><p>  FilterDispatcher選擇相應(yīng)的Action:FilterDispatcher監(jiān)聽請求,選擇相應(yīng)的Action。</p><p>  攔截

21、器攔截:攔截器是針對一些請求自動(dòng)起作用的,是為實(shí)現(xiàn)某些功能服務(wù)的,如工廠、驗(yàn)證、文件上傳等。</p><p>  Action的執(zhí)行:Action的執(zhí)行,如存儲、查詢。</p><p>  輸出視圖:結(jié)果輸出。</p><p>  返回結(jié)果:通過攔截器返回請求命令。</p><p>  顯示結(jié)果給用戶:servlet控制器發(fā)送輸出結(jié)果給用戶瀏

22、器。</p><p>  正如我們所看到的圖解,一個(gè)請求將從用戶被發(fā)送到服務(wù)器,然后這請求通過Dispatcher,在ConfigurationManager和配置文件幫助下,決定適當(dāng)?shù)腁ction。然后,被廣泛應(yīng)用的攔截器攔截,如工廠初始化,進(jìn)行驗(yàn)證。被execute方法執(zhí)行前后,攔截器啟動(dòng)工作,如儲存或從數(shù)據(jù)庫中檢索數(shù)據(jù)。輸出結(jié)果,通過攔截器的請求返回命令。這請求允許我們返回去執(zhí)行清理或額外的處理。最后,在回

23、到servlet控制容器,輸出到用戶的瀏覽器。</p><p><b>  過濾鏈:</b></p><p>  Action ContextCleanUp filter:ActionContextCleanUp過濾器是可選的,是在使用如SiteMesh等的時(shí)候才會(huì)使用的。</p><p>  FilterDispatcher:回調(diào)Action

24、Mapper來決定是否調(diào)用一個(gè)Action。若此Action是必需的調(diào)用,FilterDispatcher委托 ActionProxy。</p><p>  ActionProxy: ActionProxy從配置文件接管管理權(quán),然后ActionProxy創(chuàng)造了一個(gè)ActionInvocation。ActionInvocation過程是調(diào)用攔截器,然后選擇調(diào)用Action。ActionInvocation選擇相應(yīng)的

25、結(jié)果,然后涉及JSP或模板的結(jié)果被執(zhí)行。</p><p>  現(xiàn)在大家可能會(huì)困惑,我們要怎樣配置過濾器呢?答案就是:在web.xml文件里配置。接下來介紹一個(gè)簡單的過濾器配置:</p><p><b>  <filter></b></p><p>  <filter-name>struts2</filter-nam

26、e></p><p>  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></p><p><b>  </filter></b></p><p>  <filter-mapping><

27、;/p><p>  <filter-name>struts2</filter-name></p><p>  <url-pattern>/*</url-pattern></p><p>  </filter-mapping></p><p>  Struts 2的優(yōu)勢</p>

28、<p>  最新版本Struts 2.0融合 Struts Action和Webwork。根據(jù)在Struts2發(fā)布公告,一些關(guān)鍵的概念和特點(diǎn)是:</p><p>  Simplified Design :編程抽象類代替了接口是struts1框架設(shè)計(jì)問題之一已經(jīng)在struts2 的框架解決了。大部分的struts2類都是基于接口和它的大部分核心接口是與HTTP獨(dú)立的。類是stru

29、ts2 Action框架獨(dú)立和POJOs看起來簡單??蚣懿考急M量保持寬松耦合。</p><p>  Simplified Actions:Action是簡單的POJOs。任何帶execute()方法的java類都能作為Action類。即使我們不需要實(shí)現(xiàn)接口??刂品崔D(zhuǎn)也會(huì)注入的Action類。這使Action中立到基本框架。</p><p>  No more ActionForms: s

30、truts2框架里沒有ActionForms。簡單的JavaBean直接設(shè)置屬性。沒有必要使用所有字符串屬性。</p><p>  Simplified testability: Struts2 Action 是與HTTP非關(guān)聯(lián)的松耦合框架, 這就使得測試struts框架簡單容易,無需引入虛擬對象。</p><p>  Intelligent Defaults: 多數(shù)配置的元素有一個(gè)默認(rèn)值

31、,根據(jù)需要,它們都可以被設(shè)置。甚至有基于xml的默認(rèn)配置文件,即可根據(jù)需要自動(dòng)默認(rèn)設(shè)置。</p><p>  Improved results:不像ActionForwards,Struts2提供靈活性多種類型結(jié)果輸出。</p><p>  Better Tag features:struts2標(biāo)簽增加了sheet-driven功能,這樣我們就可以用較少的代碼頁創(chuàng)造一致風(fēng)格。Struts2

32、標(biāo)簽是具有更強(qiáng)的功能和結(jié)果導(dǎo)向。struts2標(biāo)簽標(biāo)記能夠改變樣式表。自定義標(biāo)簽標(biāo)記可調(diào)的編輯FreeMarker模版定制標(biāo)簽。JSP和FreeMarker標(biāo)簽也是兩個(gè)完全支持。</p><p>  Annotations introduced : 在struts2應(yīng)用程序里,可以使用Java 5版本以上支持的注釋來替代XML和Java屬性配置。注釋最低限度地使用xml。</p><p>

33、  QuickStart:許多變化,可以直接該沒有必要重新啟動(dòng)Web容器。</p><p>  customizing controller: Struts1定制請求處理器對應(yīng)每個(gè)模塊,Struts2定制請求處理每Action,如果有必要。</p><p>  Easy Spring integration: Struts2 Action是Spring-aware的, 只需要添加的Spri

34、ng Bean !</p><p>  Easy plugins: Struts2只要添加相應(yīng)的JAR能擴(kuò)展。不做人工配置。</p><p>  Struts 1.x VS Struts 2.x</p><p>  Servlet Dependency:</p><p>  Struts 1的Action類依賴于servlet API以Htt

35、pServletRequest,HttpServletResponse作參數(shù)傳給execute方法當(dāng)Action被調(diào)用時(shí)。Struts 2的Action不和容器有關(guān)。Servlet上下文被表現(xiàn)簡單的Maps,允許Action被獨(dú)立的測試。Struts 2的Action可以訪問最初的請求和相應(yīng),如果需要的話。然而,其他的架構(gòu)元素少或者排除直接訪問HttpServletRequest或者HttpServletResponse的需要</

36、p><p>  2. Action classes:</p><p>  Struts 1要求Action類要擴(kuò)展自一個(gè)抽象基類。Struts 1的一個(gè)共有的問題是面向抽象類編程而不是面向接口編程。Struts 2的Action類實(shí)現(xiàn)了一個(gè)Action接口,連同其他接口一起實(shí)現(xiàn)可選擇和自定義的服務(wù)。Struts 2提供一個(gè)名叫ActionSupport的基類實(shí)現(xiàn)一般使用的接口。雖然,Actio

37、n接口不是必須的。任何使用execute方法的POJO對象可以被當(dāng)作Struts 2的Action對象使用。</p><p>  3. Validation:</p><p>  Struts 1支持手動(dòng)驗(yàn)證憑借ActionForm的validate方法,或者通過擴(kuò)展的公用驗(yàn)證器。類可以有不同的驗(yàn)證上下文未相同的類,但是不能不能包括驗(yàn)證子對象。Struts 2支持手動(dòng)驗(yàn)證憑借validat

38、e方法和XWork驗(yàn)證框架。Xwork驗(yàn)證框架支持一連串的驗(yàn)證子屬性使用的驗(yàn)證了屬性類的類型和嚴(yán)正上下文而定義。</p><p>  4.Threading Model:</p><p>  Struts 1 Action類是單例類,因只有一個(gè)示例控制所有的請求。單例類策略造成了一定的限制且給開發(fā)帶來了額外的煩惱。Action資源必須是程安全或者同步的。Struts 2 Action對象每

39、一個(gè)請求都實(shí)例化對象,所以沒有程安全的問題。(實(shí)踐中,servlet容器生許多丟的對象對于每一個(gè)請求,多于一個(gè)的對象并不影響垃圾收集)</p><p>  5. Testability:</p><p>  測試Struts 1的主要障礙是execute方法暴露了Servlet API。第三方的擴(kuò)展,Struts測試用例,提供Struts 1的集合對象。Struts 2的Action可以通

40、過實(shí)例化Action測試,設(shè)置屬性,然后調(diào)用方法。依賴注入的支持也是測試變得更簡單。</p><p>  6. Harvesting Input:</p><p>  Struts 1使用ActionForm對象捕獲輸入。像Action一樣,所有的ActionForm必須擴(kuò)展基類。其他的JavaBean不能作ActionForm使用,開發(fā)者經(jīng)常創(chuàng)建多余的類捕獲輸入。DynaBeans可以被

41、用來做替代ActionForm的類創(chuàng)建。但是開發(fā)者可以重新描述已經(jīng)存在的JavaBean。 </p><p>  Struts 2 Action屬性作輸入屬性,排除第二個(gè)輸入對象的需要。輸入屬性可能有豐富的對象類型這些類型有他們自己的屬性。Action的屬性可以通過標(biāo)簽庫訪問。Struts 2也支ActionForm形式。豐富的對象類型,包含業(yè)務(wù)或者域?qū)ο螅梢员划?dāng)作輸入或者輸出對象使用。饃型驅(qū)動(dòng)特性簡化標(biāo)簽對P

42、OJO輸入對象的引用。</p><p>  7. Expression Language:</p><p>  Struts 1整和JSTL,所以它使用JSTL的表達(dá)式語言。表達(dá)式語言有基本的圖形對象移動(dòng),但是相對很弱的集合和被索引的屬性支持。 Struts 2使用JSTL,但是框架也支持更大和更靈活的表達(dá)式,叫做“對象圖形符號語言”(OGNL)。</p><p>

43、  8. Binding values into views:</p><p>  Struts 1使用標(biāo)準(zhǔn)JSP機(jī)制來綁定對象到頁面上下文。Struts 2使用“ValueStack”技術(shù)了標(biāo)簽庫可以不用鏈接你的視圖到對象的表現(xiàn)類型訪問值。ValueStack策略允許重用視圖。</p><p>  9. Type Conversion:</p><p>  Str

44、uts 1的ActionForm屬性經(jīng)常都是String的。Struts 1使用Commons-Beanutils類型轉(zhuǎn)換。轉(zhuǎn)換每一個(gè)類,不是每一個(gè)實(shí)例配置。Struts 2使用OGNL類型轉(zhuǎn)換??蚣馨D(zhuǎn)換器基本的和共同的對象類型和原始類型。</p><p>  10. Control Of Action Execution:</p><p>  Struts 1支持獨(dú)立的請求處理器對于

45、每一個(gè)模型,但是所有在模型中的Action必須共享同一個(gè)生命周期。Struts 2支持在每一個(gè)Action基礎(chǔ)上憑借攔截棧創(chuàng)建不同的生命周期。自定義??梢员粍?chuàng)建且使用不同的所需 的Action。</p><p><b>  譯文原件復(fù)印件</b></p><p>  Apache Struts 2</p><p>  “Apache Strut

46、s 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications ov

47、er time” - The Apache Software Foundation.</p><p>  4.1 Introduction</p><p>  Apache Struts is an open-source framework that is used for developing Java web application. Originally developed by

48、the programmer and author Craig R. McClanahan, this was later taken over by the Apache Software Foundation in 2002. Struts have provided an excellent framework for developing application easily by organizing JSP and Serv

49、let based on HTML formats and Java code. Strut1 with all standard Java technologies and packages of Jakarta assists to create an extensible development environment</p><p>  4.1.1 History of Struts 2</p&g

50、t;<p>  Since arriving on the scene in 2000, Apache Struts has enjoyed a very successful run, by most any standard, helping to build many, if not most, of the Java-based web applications deployed today. Its histor

51、y tells of how Struts provided a solid framework to organize the mess of JSP and Servlets to make developing applications, which used mostly server-generated HTML with a touch JavaScript for client-side validation, easie

52、r to develop and maintain. As time moved forward, and customer demands of w</p><p>  At that time, Struts developers were also working on Apache Shale, a web framework</p><p>  based off JSF, as

53、 a Struts subproject, along side Struts Action 1 (now called Struts 1) and Struts Action 2 (the graduated WebWork 2 code). Unfortunately, these subprojects were confusion to the developer and user community, accustomed t

54、o the name “Struts” referring to a single framework. After an attempt to unify the Struts Action 2 and Shale subprojects into a single Struts 2 framework, the Shale developers felt it would be better if they were their o

55、wn top level project where they are today. </p><p>  Today, the Apache Struts project has two major versions of its framework, but it is one action-based framework project. WebWork continues to deliver patch

56、 releases, and will certainly continue to do so until Struts 2 goes on, but all new development takes place on the Struts 2 code. Since the initial appearance, the Struts 2 code has added major features including a plugi

57、n framework, new APIs, and better Ajax tags and will still keep on improving.</p><p>  4.2 Struts 2 features</p><p>  4.2.1 The MVC Architecture</p><p>  Inherited from Struts 1, St

58、ruts 2 is also an open source framework used for developing J2EE web applications using Model View Controller design pattern. The main aim of the MVC architecture is to separate the business logic and application data fr

59、om the presentation data to the user. Here are the reasons why we should use the MVC design pattern. They are reusable : When the problems recurs, there is no need to invent a new solution, we just have to follow the pat

60、tern and adapt it as necessary. T</p><p>  4.2.1.1 Model</p><p>  The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can

61、be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the

62、 presentation data and how that data will be displayed to the browser.</p><p>  4.2.1.2 View</p><p>  The view represents the presentation of the application. The view object refers to the model

63、. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we c

64、an say that it is the responsibility of the of the view’s to maintain the consistency in its presentation when the model changes.</p><p>  4.2.1.3 Controller</p><p>  Whenever the user sends a r

65、equest for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken

66、on the data, the controller is responsible for directing the appropriate view to the user. In GUIs, the views and the controllers often work very closely together.</p><p>  4.2.2 How this model applied in St

67、ruts 2</p><p>  The Struts 2 Controller Components Whenever an user request for something, the request is handled by FilterDispatcher. When the FilterDispatcher receives the request, it intercepts the URL an

68、d based on the Struts Configuration files, it gives the handling of the request to the Action class. Action class is a part of the controller and is responsible for communicating with the model layer. The Struts 2 View C

69、omponents The view components are responsible for presenting information to the users and</p><p>  4.2.3 What Struts 2 could bring</p><p>  Struts 2 contains the combined features of Struts Ti a

70、nd WebWork 2 projects that advocates higher level application by using the architecture of WebWork2 with features including a plugin framework, a new API, AJAX tags etc. Hence, Apache Strut 2 is a dynamic, extensible fra

71、mework for a complete application development from building, deploying and maintaining. The Strut 2 framework is designed for the compilation of the entire development cycle including of building, developing and maintain

72、ing th</p><p>  Tags - Tags in Strut 2 allow creating dynamic web applications with less number of coding. Not only these tags contain output data but also provide style sheet driven</p><p>  ma

73、rkup that in turn helps in creating pages with less code. Here the tags also support</p><p>  validation and localization of coding that in turn offer more utilization. The less number of codes also makes it

74、 easy to read and maintain.</p><p>  MVC – The Model View Controller in Strut 2 framework acts as a coordinator between</p><p>  application’s model and web view. Its Controller and View compone

75、nts can come together with other technology to develop the model. The framework has its library and markup tags to present the data dynamically. I Configuration – Provides a deployment descriptor to initialize resources

76、in XML format. The initialization takes place simply by scanning all the classes using Java packages or you can use an application configuration file to control the entire configuration. Its</p><p>  general

77、-purpose defaults allow using struts directly Out of the box. Configuration files are re-loadable that allows changes without restarting a web container.</p><p>  Apart from that, there are also a lot of oth

78、er features that make web development more easy: I All framework classes are based on interfaces and core interfaces are independent from HTTP. I Check boxes do not require any kind of special application for false value

79、s. I Any class can be used as an action class and one can input properties by using any JavaBean directly to the action class. I Strut 2 actions are Spring friendly and so easy to Spring integration.</p><p>

80、  AJAX theme enables to make the application more dynamic. Portal and servlet deployment are easy due to automatic portlet support without altering code. The request handling in every action makes it easy to customize, w

81、hen required.</p><p>  4.2.4 Looking into Struts 2 architecture</p><p>  As Struts and Webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and el

82、egant for the development of enterprise web application of any size. In this section we are going to discuss the architecture of Struts 2 Framework. First, let’s take a look at a request Lifecycle in Struts 2 application

83、s:</p><p>  1. User Sends request: User sends a request to the server for some resource.</p><p>  2. FilterDispatcher determines the appropriate action: The FilterDispatcher looks at</p>

84、<p>  the request and then determines the appropriate Action.</p><p>  3. Interceptors are applied: Interceptors are configured for applying the common functionalities</p><p>  such as work

85、flow, validation, file upload etc. are automatically applied to the</p><p><b>  request.</b></p><p>  4. Execution of Action: Then the action method is executed to perform the databa

86、se</p><p>  related operations like storing or retrieving data from the database.</p><p>  5. Output rendering: Then the Result renders the output.</p><p>  6. Return of Request: Th

87、en the request returns through the interceptors in the reverse</p><p>  order. The returning request allows us to perform the clean-up or additional processing.</p><p>  7. Display the result to

88、 user: Finally the control is returned to the servlet container,</p><p>  which sends the output to the user browser.</p><p>  Figure 4.1: Struts 2 high level overview of request processing</

89、p><p>  For a more detail picture 1 of the whole process, the following diagram depicts the architecture</p><p>  of Struts 2 Framework and also shows the the initial request goes to the servlet<

90、;/p><p>  container such as tomcat, which is then passed through standard filer chain.</p><p>  1Diagrams and some explanation used in this section were taken from Struts 2 tutorial at www.roseindi

91、a.net.</p><p>  4.2: Struts 2 Architecture</p><p>  As we can see from the diagram, a request will be sent from an user to server, this request</p><p>  then pass to FilterDispatche

92、r to determine the appropriate action with the help of ConfigurationManager and configuration files, after that, interceptors are applied for functionalities such as workflow, validation. Then the action method is execut

93、ed to perform tasks such as database related operations like storing or retrieving data from the database. The result renders the output, the request returns through the interceptors in the reverse order. The returning r

94、equest allows us to perform the </p><p>  4.2. STRUTS 2 FEATURES </p><p>  ActionProxy: The ActionProxy takes help from Configuration Files manager, which is initialized from the struts.xml. The

95、n the ActionProxy creates an ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action. The the ActionInvocation looks for p

96、roper result. Then the result is executed, which involves the rendering of JSP or templates. Now some of us might wonder, how do we get this filters to work? The</p><p><b>  <filter></b><

97、;/p><p>  <filter-name>struts2</filter-name></p><p>  <filter-class></p><p>  org.apache.struts2.dispatcher.FilterDispatcher</p><p>  </filter-class&g

98、t;</p><p><b>  </filter></b></p><p>  <filter-mapping></p><p>  <filter-name>struts2</filter-name></p><p>  <url-pattern>/*<

99、;/url-pattern></p><p>  </filter-mapping></p><p>  4.2.5 What is so good about Struts 2</p><p>  The new version Struts 2.0 is a combination of the Struts action framework

100、and Webwork. According to the Struts 2 release announcement, some key concepts and features are:</p><p>  Simplified Design - Programming the abstract classes instead of interfaces is one of design problem o

101、f struts1 framework that has been resolved in the struts 2 framework. Most of the Struts 2 classes are based on interfaces and most of its core interfaces are HTTP independent. Struts 2 Action classes are framework indep

102、endent and are simplified to look as simple POJOs. Framework components are tried to keep loosely coupled. Simplified Actions - Actions are simple POJOs. Any java class with execu</p><p>  No more ActionForm

103、s - ActionForms feature is no more known to the struts2 framework.</p><p>  Simple JavaBean flavored actions are used to put properties directly. No need to use all String properties.</p><p>  S

溫馨提示

  • 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. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論