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

下載本文檔

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

文檔簡介

1、<p>  一種基于Hibernate、Struts和Spring的J2EE應(yīng)用開發(fā)框架</p><p>  隨著Java技術(shù)的逐漸成熟與完善,作為建立企業(yè)級應(yīng)用的標(biāo)準(zhǔn)平臺,J2EE平臺得到了長足的發(fā)展。借助于J2EE規(guī)范中包含的多項(xiàng)技術(shù):Enterprise JavaBean(EJB)、Java Servlets(Servlet)、Java Server Pages(JSP)、Java Message

2、 Service(JMS)等,開發(fā)出了許多應(yīng)用系統(tǒng)。但是,在傳統(tǒng)J2EE應(yīng)用的開發(fā)過程中也出現(xiàn)了一些問題:</p><p>  (1)數(shù)據(jù)模型和邏輯模型之間的矛盾。目前使用的數(shù)據(jù)庫基本上都是關(guān)系型數(shù)據(jù)庫,而Java本質(zhì)上是一種面向?qū)ο蟮恼Z言,對象在存儲(chǔ)和讀取時(shí)使用SQL和JDBC進(jìn)行數(shù)據(jù)庫操作,降低了編程的效率以及系統(tǒng)的可維護(hù)性;</p><p>  (2)傳統(tǒng)的J2EE應(yīng)用多采用基于EJ

3、B的重量級框架,這種框架適合于開發(fā)大型企業(yè)應(yīng)用,但是使用EJB容器進(jìn)行開發(fā)和調(diào)試需要耗費(fèi)大量時(shí)間。為了降低代碼的耦合性,提高系統(tǒng)的開發(fā)效率,本文提出了一種基于Struts框架、Hibernate框架和Spring框架的J2EE應(yīng)用開發(fā)策略。</p><p>  Hibernate 框架</p><p>  Hibernate是一個(gè)數(shù)據(jù)持久層框架,是一種實(shí)現(xiàn)對象和關(guān)系之間映射(O/R Map

4、ping)的工具,它對JDBC進(jìn)行了輕量級的對象封裝,使程序員可以使用對象編程思想來操作數(shù)據(jù)庫。它不僅提供了從Java類到數(shù)據(jù)表的映射,也提供了數(shù)據(jù)查詢和恢復(fù)機(jī)制。相對于使用JDBC和SQL來操作數(shù)據(jù)庫,使用Hibernate能大大的提高實(shí)現(xiàn)的效率。Hibernate框架用配置文件的形式來定義Java對象和數(shù)據(jù)表之間的映射關(guān)系,同時(shí)在更深的層面將數(shù)據(jù)表之間的關(guān)系解釋為Java對象之間的繼承及包含等關(guān)系。通過使用HQL語句將復(fù)雜的關(guān)系算法

5、用對象的方式描述,在很大程度上簡化了對數(shù)據(jù)的查詢,加快了開發(fā)的效率。在Hibernate中有一個(gè)簡單而直觀的API,用于對數(shù)據(jù)庫所表示的對象執(zhí)行查詢。要?jiǎng)?chuàng)建或修改這些對象,只需在程序中與它們進(jìn)行交互,然后告訴Hibernate保存即可。這樣,大量封裝持久化操作的業(yè)務(wù)邏輯不再需要編寫煩瑣的JDBC語句,從而使數(shù)據(jù)持久層得到了極大的簡化。 </p><p>  用Struts實(shí)現(xiàn)MVC架構(gòu) MVC(Model-Vie

6、w-Controller)由Trygve Reenskaug提出,首先被應(yīng)用在SmallTalk-80環(huán)境中,是許多交互和界面系統(tǒng)的構(gòu)成基礎(chǔ)。根據(jù)界面設(shè)計(jì)可變性的需求,MVC把交互系統(tǒng)的組成分解成模型、視圖、控制器三部分。模型(Model)是軟件所處理問題邏輯在獨(dú)立于外在顯示內(nèi)容和形式情況下的內(nèi)在抽象,封裝了問題的核心數(shù)據(jù)、邏輯和功能的計(jì)算關(guān)系,獨(dú)立于具體的界面表達(dá)和I/O操作。視圖(View)把表示模型數(shù)據(jù)及邏輯關(guān)系和狀態(tài)的信息及特定

7、形式展示給用戶。它從模型獲得顯示信息,對于相同的信息可以有多個(gè)不同的顯示形式或視圖。控制器(Controller)是處理用戶與軟件的交互操作的,其職責(zé)是控制提供模型中任何變化的傳播,確保用戶界面于模型間的對應(yīng)聯(lián)系;它接受用戶的輸入,將輸入反饋給模型,進(jìn)而實(shí)現(xiàn)對模型的計(jì)算控制,是使模型和視圖協(xié)調(diào)工作的部件。通常一個(gè)視圖對應(yīng)一個(gè)控制器。模型、視圖與控制器的分離,使得一個(gè)模型可以具有多個(gè)顯示視圖。如果用戶通過某個(gè)視圖的控制器改變了模型的數(shù)據(jù),

8、所有其它依賴于這些數(shù)據(jù)的視圖都應(yīng)反映到這些變化。因此,無論何時(shí)發(fā)</p><p><b>  Struts框架</b></p><p>  Struts框架最早是作為Apache Jakarta項(xiàng)目的組成部分問世運(yùn)做,它繼承了MVC的各項(xiàng)特性,并根據(jù)J2EE的特點(diǎn),做了相應(yīng)的變化與擴(kuò)展。Struts框架很好的結(jié)合了Jsp,Java Servlet,Java Bean,

9、Taglib等技術(shù)。在Struts中,承擔(dān)MVC中控制器角色的是ActionServlet。ActionServlet是一個(gè)通用的控制組件。這個(gè)控制組件提供了處理所有發(fā)送到Struts的HTTP請求的入口點(diǎn),它截取和分發(fā)這些請求到相應(yīng)的動(dòng)作類(這些動(dòng)作類都是Action類的子類)。另外控制組件也負(fù)責(zé)用相應(yīng)的請求參數(shù)填充Action Form(FromBean),并傳給動(dòng)作類(ActionBean)。動(dòng)作類訪問核心商業(yè)邏輯,即訪問Java

10、 Bean或調(diào)用EJB。最后動(dòng)作類把控制權(quán)傳給后續(xù)的JSP文件,由JSP文件生成視圖。所有這些控制邏輯利用Struts-config.xml文件來配置。在Struts框架中,視圖主要由JSP生成頁面完成,Struts提供豐富的JSP標(biāo)簽庫,這有利于分開表現(xiàn)邏輯和程序邏輯。模型以一個(gè)或多個(gè)Java Bean的形式存在。在Strut</p><p><b>  Spring 框架</b><

11、/p><p>  Spring明顯區(qū)別于其他輕量級application framework, 它將專注于web的支持,與struts 和 webwork有著明顯的區(qū)別。 </p><p>  在與struts、webwork的對比上,Spring是一個(gè)服務(wù)于所有層面的application framework:提供了bean的配置基礎(chǔ),AOP的支持,JDBC的提取框架,抽象事務(wù)支持等等。它有

12、一個(gè)非常顯著的特點(diǎn):在某個(gè)層面上如果你不需要Spring的支持,你就可以不使用Spring的class,只使用它的某一部分的功能。 從它的設(shè)計(jì)理念,你可以看到Spring 幫助你實(shí)現(xiàn)了真正的邏輯層和web層的分離。例如:一個(gè)校驗(yàn)應(yīng)用將不用依靠controllers就可以實(shí)現(xiàn)。這樣的目標(biāo)更好的重用和易測,過分依靠不必要的容器和框架將不能實(shí)現(xiàn)這一點(diǎn)。</p><p>  當(dāng)然,Spring 有自己的web支持和通???/p>

13、架模式細(xì)致完整。然而,Spring替換struts、webwork或者其他的web方案非常容易。對于Spring的web支持或者不同的地方,Spring 允許你在web容器里面建立一個(gè)中間層,在測試環(huán)境或者標(biāo)準(zhǔn)獨(dú)立的應(yīng)用里面來設(shè)置重用你的商務(wù)邏輯.還有在J2EE環(huán)境里面,你的商務(wù)邏輯不必依靠容器提供的服務(wù),像JTA ,EJB的支持。良好的構(gòu)架的web應(yīng)用可以運(yùn)行在任何容器上,如,Tomcat 或者 Resin。值得注意的是,Spring

14、 不是和已經(jīng)存在的解決方案進(jìn)行競爭. 我們鼓勵(lì)結(jié)合標(biāo)準(zhǔn)的技術(shù),如,Servlet,JSP, JTA,JNDI,JDBCand JDO和非常匹配的工具,如,Hibernate, Velocity, Log4J, and Caucho's Hessian/Burlap。這個(gè)框架的的設(shè)計(jì)思想是在你的應(yīng)用需要改良的時(shí)候,你將會(huì)做一些技術(shù)的選擇,例如,如果你需要分布式事務(wù)處理,你可能需要用Spring的Jta TransactionMan

15、ager 來實(shí)現(xiàn)JTA服務(wù)?;蛘哂肈ataSource TransactionMa</p><p>  Spring 框架通過配置操作mappings,展示resolution,本地化和模版集成圍繞著分派請求操作的servlet-DispatcherServlet設(shè)計(jì)的。缺省的操作是一個(gè)非常簡單的控制接口, 他只提供了ModelAndView handleRequest (request, response)方法

16、。這將用于一個(gè)應(yīng)用的控制,但是,如果你想包含多個(gè)層次的控制,AbstractController,AbstractCommandController, MultiActionController,SimpleFormController,AbstractWizardFormController將幫助你完成.應(yīng)用控制將代表那些子系統(tǒng)。注意,你可以選擇一個(gè)適當(dāng)?shù)幕?如果你沒有web form,你就不必用FormController,這就是

17、和Struts最大的不同。你可以通過命令或者form對象來操作任何對象,這不需要接口工具或者一個(gè)基礎(chǔ)類的驅(qū)動(dòng)。Spring的數(shù)據(jù)綁定非常靈活。舉例來說,它描述了具有在應(yīng)用范圍內(nèi)的校驗(yàn)錯(cuò)誤的輸入機(jī)制,但不是系統(tǒng)錯(cuò)誤,所以在你的form對象里面你不必復(fù)</p><p>  關(guān)于視圖:Spring的視圖方案非常的靈活。一個(gè)控制器執(zhí)行可以通過response 返回ModelAndView對象null就可以直接寫到一個(gè)視圖

18、里,在一般情況下,一個(gè)ModelAndView實(shí)例結(jié)合了一個(gè)view和一個(gè)model Map,包含了bean name 和通訊對象(像命令或者form,參考數(shù)據(jù)等等)。View名稱是非常高端的配置,不是通過bean name,一個(gè)properties 文件就是通過你自己的ViewResolver.這個(gè)抽象的model Map 允許你在視圖層面完成提取,沒有任何的爭辯JSP/Velocity或者其他,每一種都可以直接完整使用.這個(gè)mode

19、l Map 還可以簡單得得到適當(dāng)?shù)母袷交瘮?shù)據(jù)的轉(zhuǎn)換,像JSP 請求屬性或者Velocity 模版模式. </p><p>  如果你不想用Spring的 web MVC,但是想借用Spring嫁接其他的解決方案,你可以非常簡單地通過Spring繼承你自己的web 框架,你可以非常簡單地通過ContextLoaderListener啟動(dòng)一個(gè)Spring root application context,并且,通過S

20、truts 或者WebWork 的action 利用ServletContext 屬性(或者Spring 的helper方法)存取它。值得注意的是, 這里沒有任何的"plugins"被調(diào)用,因此沒有專門的集成:來自web層的視圖, 你可以簡單的將Spring作為一個(gè)管理application context 實(shí)例入口點(diǎn)的類庫。所有你注冊bean和Spring服務(wù)都可以在不需要Spring的web MVC的情況下都可以

21、輕松掌握。Spring不是和Struts 、WebWork這些應(yīng)用進(jìn)行競爭,它將作為一個(gè)純web框架應(yīng)用于很多領(lǐng)域,因?yàn)樗恍枰渲脭?shù)據(jù)存儲(chǔ)和事務(wù)操作,所以,你可以利用Spring提供的中間層和數(shù)據(jù)存儲(chǔ)層來豐富你的應(yīng)用,甚至用JDBC或者Hibernate進(jìn)行事務(wù)抽象。</p><p>  如果僅僅聚焦于web支持,Spring的一些顯著特點(diǎn)是清楚分離:controller,validator,command o

22、bject,form object,model object,和 DispatcherServlet,handler mapping vs view resolver等等強(qiáng)大而且直接的框架和作為JavaBeans的應(yīng)用配置,包括簡單的參照和應(yīng)用內(nèi)容,例如,從web控制器到業(yè)務(wù)對象和數(shù)據(jù)校驗(yàn)。適應(yīng)性,無論什么樣的控制器你都需要得到代替Action/ActionForm所做的每件事情的方案(簡單,命令,form,范例,多重action,或者

23、定制一個(gè)) 重用業(yè)務(wù)邏輯代碼,不需要復(fù)制,你可以用已經(jīng)有的業(yè)務(wù)邏輯對象作為命令或則form對象代替反射特定的ActionForm子類??捎喼频慕壎ê蛿?shù)據(jù)校驗(yàn)作為應(yīng)用級的輸入機(jī)制的錯(cuò)誤校驗(yàn),固定日期和數(shù)字綁定,例如,通過手動(dòng)檢查和轉(zhuǎn)換業(yè)務(wù)對象來替換單個(gè)的string??捎喼频牟僮?可訂制的視圖方案:通過name/value Map靈活的模型傳送,用一個(gè)簡單的方法從簡單到復(fù)雜操作映射和視圖方案策略。</p><p>

24、  以在J2EE應(yīng)用中非常普遍的用戶登錄過程為例來說明上述體系結(jié)構(gòu)是如何具體運(yùn)用的。登錄的流程非常清晰:用戶從登錄頁面login.jsp輸入登錄信息,系統(tǒng)對登錄信息進(jìn)行驗(yàn)證,如果正確則成功登錄,否則提示相應(yīng)錯(cuò)誤信息。在開發(fā)過程中,使用Eclipse做為開發(fā)環(huán)境,同時(shí)加載了對Struts、Spring及Hibernate提供更好的控制和支持的第三方插件MyEclipse,Web服務(wù)器使用Tomcat,數(shù)據(jù)庫選用了Mysql。首先對Hibe

25、rnate進(jìn)行配置,只需要對系統(tǒng)自動(dòng)生成的hibernate.cfg.xml進(jìn)行修改,配置好數(shù)據(jù)庫連接的各種參數(shù)以及定義數(shù)據(jù)映射文件。由于Hibernate所帶的連接池主要用于測試,性能不是很好,可以通過JNDI將其修改為使用Tomcat的連接池。</p><p>  A Development Frame Application Based on the Hibernate、the Struts and the

26、 Spring J2EE</p><p>  One preface along with the Java technique of gradual mature and perfect. Be establishment business enterprise class application of standard terrace,the J2 EE terrace got substantial of

27、development .Several technique asked for help from to include in the J2 EE norm : Enterprise JavaBean (EJB), Java Servlets (Servlet), Java Server Pages(JSP), Java Message Service(JMS)etc., development many application sy

28、stem.But, also appeared some problem in the tradition J2 the EE the application of the developm</p><p>  1)the antinomy of of data model and logic model. Currently the database of usage basically and all is

29、relation type database, but the Java be essentially a kind of the language which face to object, object at saving with read usage SQL and JDBC carry on a database operation and lowered plait distance of efficiency and sy

30、stem of can maintenance;</p><p>  2)tradition of J2 EE application much the adoption is according to the EJB heavy weight frame, this kind of frame suitable for develop a large business enterprise applicatio

31、n, but usage the EJB container carry on development and adjust to try to need to be waste a great deal of time.For lowering the Ou of code to match sex, exaltation system of development efficiency, this text put forward

32、one kind EE according to the J2 of the Struts frame 、the Hibernate frame and the Spring frame application d</p><p>  The Hibernate Frame</p><p>  Data's holding out for long time layer and H

33、ibernate is one piece according to hold out for long time layer frame, is a kind of realization object and relation of the tool which reflect to shoot(O/R Mapping), it carried on the object of the lightweight to pack to

34、the JDBC and make procedure member can usage object plait distance thought to operation database. It not only provided to shoot from Java to reflect of data form, but also provided a data a search and instauration mechan

35、ism. Opposite in</p><p>  Use the Struts realization MVC structure MVC(Model-View-Controller) is put forward by the Trygve Reenskaug, first drive application in the environment SmallTalk-80, is many to hand

36、over with each other with interface system of constitute foundation. According to the need of variable of the interface design, MVC hand over with each other constitute of system to resolve into model and see diagram, co

37、ntroller three part. Model(Model) is software processing problem logic at independence in outside m</p><p>  The Struts Frame</p><p>  The Struts frame is to be the item of Apache Jakarta to con

38、stitute part to publish luck to do at the earliest stage, it inherited MVC of each item characteristic, and did according to the characteristics of J2 EE correspond of variety with expand. The Struts frame was good to co

39、mbine Jsp , Java Servlet , Java Bean, Talia etc. technique. In the Struts, what to undertake the controller role in the MVC be an ActionServlet. The ActionServlet is an in general use control module. This control module

40、p</p><p>  the Spring Frame</p><p>  Spring isn't particularly a web framework but a generic lightweight application framework with dedicated web support, and show the architectural differen

41、ces to Struts and WebWork</p><p>  In contrast to Struts or WebWork, Spring is an application framework for all layers: It offers a bean configuration foundation, AOP support, JDBC abstraction framework, abs

42、tract transaction support etc. It is a very non-intrusive effort: Your application classes do not need to depend on any Spring classes if not necessary, and you can reuse every part on its own if you like to. From its ve

43、ry design, the framework encourages clean separation of tiers, most importantly web tier and business logic.</p><p>  Of course, Spring's own web support is nicely integrated with the framework's gen

44、eral patterns. Nevertheless, replacing the web solution with Struts, WebWork, or the like is easy. Both with Spring's web support or a different one, Spring allows for building a true dedicated middle tier in the web

45、 container, with the option to reuse exactly the same business logic in test environments or standalone applications. And within J2EE, your business logic will not unnecessarily depend on container servi</p><p

46、>  Spring's web framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, and locale and theme resolution. The default handler is a

47、 very simple Controller interface, just offering a "ModelAndView handleRequest(request,response)" method. This can already be used for application controllers, but you will prefer the included implementation hi

48、erarchy, consisting of AbstractController, AbstractCommandController, MultiActio</p><p>  You can take any object as command or form object: There's no need to implement an interface or derive from a bas

49、e class. Spring's data binding is highly flexible, e.g. it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. So you don't need to duplicate your business

50、objects' properties as Strings in your form objects, just to be able to handle invalid submissions, or to convert the Strings properly. Instead, it's often preferable to bind </p><p>  Regarding view

51、s: Spring's view resolution is extremely flexible. A Controller implementation can even write a view directly to the response, returning null as ModelAndView. In the normal case, a ModelAndView instance consists of a

52、 view name and a model Map, containing bean names and corresponding objects (like a command or form, reference data, etc). View name resolution is highly configurable, either via bean names, via a properties file, or via

53、 your own ViewResolver implementation. The abstrac</p><p>  If you don't want to use Spring's web MVC but intend to leverage other solutions that Spring offers, you can integrate the web framework of

54、 your choice with Spring easily. Simply start up a Spring root application context via its ContextLoaderListener, and access it via its ServletContext attribute (or Spring's respective helper method) from within a St

55、ruts or WebWork action. Note that there aren't any "plugins" involved, therefore no dedicated integration: From the view of the web layer, you'll</p><p>  If just focussing on the web suppo

56、rt, some of Spring's unique features are: .Clear separation of roles: controller vs validator vs command object vs form object vs model object, DispatcherServlet vs handler mapping vs view resolver, etc. .Powerful an

57、d straightforward configuration of both framework and application classes as JavaBeans, including easy in-between referencing via an application context, e.g. from web controllers to business objects and validators. .Ada

58、ptability, non-intrusiveness: </p><p>  With in the J2 the EE the application very widespread customer register process for example, elucidation above-mentioned system structure is how concrete usage. The pr

59、ocess of register is very clear: Customer from register page login.jsp importation register information, system to register the information carry on verification, if exactitude success register, otherwise hint correspond

溫馨提示

  • 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. 眾賞文庫僅提供信息存儲(chǔ)空間,僅對用戶上傳內(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

提交評論