计算机论文文献翻译Word文件下载.docx

上传人:b****1 文档编号:5838930 上传时间:2023-05-05 格式:DOCX 页数:18 大小:76.05KB
下载 相关 举报
计算机论文文献翻译Word文件下载.docx_第1页
第1页 / 共18页
计算机论文文献翻译Word文件下载.docx_第2页
第2页 / 共18页
计算机论文文献翻译Word文件下载.docx_第3页
第3页 / 共18页
计算机论文文献翻译Word文件下载.docx_第4页
第4页 / 共18页
计算机论文文献翻译Word文件下载.docx_第5页
第5页 / 共18页
计算机论文文献翻译Word文件下载.docx_第6页
第6页 / 共18页
计算机论文文献翻译Word文件下载.docx_第7页
第7页 / 共18页
计算机论文文献翻译Word文件下载.docx_第8页
第8页 / 共18页
计算机论文文献翻译Word文件下载.docx_第9页
第9页 / 共18页
计算机论文文献翻译Word文件下载.docx_第10页
第10页 / 共18页
计算机论文文献翻译Word文件下载.docx_第11页
第11页 / 共18页
计算机论文文献翻译Word文件下载.docx_第12页
第12页 / 共18页
计算机论文文献翻译Word文件下载.docx_第13页
第13页 / 共18页
计算机论文文献翻译Word文件下载.docx_第14页
第14页 / 共18页
计算机论文文献翻译Word文件下载.docx_第15页
第15页 / 共18页
计算机论文文献翻译Word文件下载.docx_第16页
第16页 / 共18页
计算机论文文献翻译Word文件下载.docx_第17页
第17页 / 共18页
计算机论文文献翻译Word文件下载.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

计算机论文文献翻译Word文件下载.docx

《计算机论文文献翻译Word文件下载.docx》由会员分享,可在线阅读,更多相关《计算机论文文献翻译Word文件下载.docx(18页珍藏版)》请在冰点文库上搜索。

计算机论文文献翻译Word文件下载.docx

Ifyouhaveworkedonalarge-scaleWebapplication,youunderstandthetermchange.Model-View-Controller(MVC)isadesignpatternputtogethertohelpcontrolchange.MVCdecouplesinterfacefrombusinesslogicanddata.StrutsisanMVCimplementationthatusesServlets2.2andJSP1.1tags,fromtheJ2EEspecifications,aspartoftheimplementation.YoumayneverimplementasystemwithStruts,butlookingatStrutsmaygiveyousomeideasonyourfutureServletsandJSPimplementations.

Model-View-Controller(MVC)

JSPtagssolvedonlypartofourproblem.Westillhaveissueswithvalidation,flowcontrol,andupdatingthestateoftheapplication.ThisiswhereMVCcomestotherescue.MVChelpsresolvesomeoftheissueswiththesinglemoduleapproachbydividingtheproblemintothreecategories:

∙Model

Themodelcontainsthecoreoftheapplication'

sfunctionality.Themodelencapsulatesthestateoftheapplication.Sometimestheonlyfunctionalityitcontainsisstate.Itknowsnothingaboutthevieworcontroller.

∙View

Theviewprovidesthepresentationofthemodel.Itisthelookoftheapplication.Theviewcanaccessthemodelgetters,butithasnoknowledgeofthesetters.Inaddition,itknowsnothingaboutthecontroller.Theviewshouldbenotifiedwhenchangestothemodeloccur.

∙Controller

Thecontrollerreactstotheuserinput.Itcreatesandsetsthemodel.

MVCModel2

TheWebbroughtsomeuniquechallengestosoftwaredevelopers,mostnotablythestatelessconnectionbetweentheclientandtheserver.Thisstatelessbehaviormadeitdifficultforthemodeltonotifytheviewofchanges.OntheWeb,thebrowserhastore-querytheservertodiscovermodificationtothestateoftheapplication.

Anothernoticeablechangeisthattheviewusesdifferenttechnologyforimplementationthanthemodelorcontroller.Ofcourse,wecoulduseJava(orPERL,C/C++orwhatever)codetogenerateHTML.Thereareseveraldisadvantagestothatapproach:

∙Javaprogrammersshoulddevelopservices,notHTML.

∙Changestolayoutwouldrequirechangestocode.

∙Customersoftheserviceshouldbeabletocreatepagestomeettheirspecificneeds.

∙Thepagedesignerisn'

tabletohavedirectinvolvementinpagedevelopment.

∙HTMLembeddedintocodeisugly.

FortheWeb,theclassicalformofMVCneededtochange.Figure4displaystheWebadaptationofMVC,alsocommonlyknownasMVCModel2orMVC2.

Strutsdetails

DisplayedinFigure6isastripped-downUMLdiagramoftheorg.apache.struts.actionpackage.Figure6showstheminimalrelationshipsamongActionServlet(Controller),ActionForm(FormState),andAction(ModelWrapper).

Figure6.UMLdiagramoftherelationshipoftheCommand(ActionServlet)totheModel(Action&

ActionForm)

TheActionServletclass

Doyourememberthedaysoffunctionmappings?

Youwouldmapsomeinputeventtoapointertoafunction.Ifyouwhereslick,youwouldplacetheconfigurationinformationintoafileandloadthefileatruntime.FunctionpointerarrayswerethegoodolddaysofstructuredprogramminginC.

LifeisbetternowthatwehaveJavatechnology,XML,J2EE,andallthat.TheStrutsControllerisaservletthatmapsevents(aneventgenerallybeinganHTTPpost)toclasses.Andguesswhat--theControllerusesaconfigurationfilesoyoudon_thavetohard-codethevalues.Lifechanges,butstaysthesame.

ActionServletistheCommandpartoftheMVCimplementationandisthecoreoftheFramework.ActionServlet(Command)createsandusesAction,anActionForm,andActionForward.Asmentionedearlier,thestruts-config.xmlfileconfigurestheCommand.DuringthecreationoftheWebproject,ActionandActionFormareextendedtosolvethespecificproblemspace.Thefilestruts-config.xmlinstructsActionServletonhowtousetheextendedclasses.Thereareseveraladvantagestothisapproach:

∙Theentirelogicalflowoftheapplicationisinahierarchicaltextfile.Thismakesiteasiertoviewandunderstand,especiallywithlargeapplications.

∙ThepagedesignerdoesnothavetowadethroughJavacodetounderstandtheflowoftheapplication.

∙TheJavadeveloperdoesnotneedtorecompilecodewhenmakingflowchanges.

CommandfunctionalitycanbeaddedbyextendingActionServlet.

TheActionFormclass

ActionFormmaintainsthesessionstatefortheWebapplication.ActionFormisanabstractclassthatissub-classedforeachinputformmodel.WhenIsayinputformmodel,IamsayingActionFormrepresentsageneralconceptofdatathatissetorupdatedbyaHTMLform.Forinstance,youmayhaveaUserActionFormthatissetbyanHTMLForm.TheStrutsframeworkwill:

∙ChecktoseeifaUserActionFormexists;

ifnot,itwillcreateaninstanceoftheclass.

∙StrutswillsetthestateoftheUserActionFormusingcorrespondingfieldsfromtheHttpServletRequest.Nomoredreadfulrequest.getParameter()calls.Forinstance,theStrutsframeworkwilltakefnamefromrequeststreamandcallUserActionForm.setFname().

∙TheStrutsframeworkupdatesthestateoftheUserActionFormbeforepassingittothebusinesswrapperUserAction.

∙BeforepassingittotheActionclass,Strutswillalsoconductformstatevalidationbycallingthevalidation()methodonUserActionForm.Note:

Thisisnotalwayswisetodo.TheremightbewaysofusingUserActionForminotherpagesorbusinessobjects,wherethevalidationmightbedifferent.ValidationofthestatemightbebetterintheUserActionclass.

∙TheUserActionFormcanbemaintainedatasessionlevel.

Notes:

∙Thestruts-config.xmlfilecontrolswhichHTMLformrequestmapstowhichActionForm.

∙MultiplerequestscanbemappedUserActionForm.

∙UserActionFormcanbemappedovermultiplepagesforthingssuchaswizards.

TheActionclass

TheActionclassisawrapperaroundthebusinesslogic.ThepurposeofActionclassistotranslatetheHttpServletRequesttothebusinesslogic.TouseAction,subclassandoverwritetheprocess()method.

TheActionServlet(Command)passestheparameterizedclassestoActionFormusingtheperform()method.Again,nomoredreadfulrequest.getParameter()calls.Bythetimetheeventgetshere,theinputformdata(orHTMLformdata)hasalreadybeentranslatedoutoftherequeststreamandintoanActionFormclass.

Figure4.MVCModel2

Struts,anMVC2implementation

Strutsisasetofcooperatingclasses,servlets,andJSPtagsthatmakeupareusableMVC2design.ThisdefinitionimpliesthatStrutsisaframework,ratherthanalibrary,butStrutsalsocontainsanextensivetaglibraryandutilityclassesthatworkindependentlyoftheframework.Figure5displaysanoverviewofStruts.

Figure5.Strutsoverview

Strutsoverview

∙Clientbrowser

AnHTTPrequestfromtheclientbrowsercreatesanevent.TheWebcontainerwillrespondwithanHTTPresponse.

TheControllerreceivestherequestfromthebrowser,andmakesthedecisionwheretosendtherequest.WithStruts,theControllerisacommanddesignpatternimplementedasaservlet.Thestruts-config.xmlfileconfigurestheController.

∙Businesslogic

Thebusinesslogicupdatesthestateofthemodelandhelpscontroltheflowoftheapplication.WithStrutsthisisdonewithanActionclassasathinwrappertotheactualbusinesslogic.

∙Modelstate

Themodelrepresentsthestateoftheapplication.Thebusinessobjectsupdatetheapplicationstate.ActionFormbeanrepresentstheModelstateatasessionorrequestlevel,andnotatapersistentlevel.TheJSPfilereadsinformationfromtheActionFormbeanusingJSPtags.

TheviewissimplyaJSPfile.Thereisnoflowlogic,nobusinesslogic,andnomodelinformation--justtags.TagsareoneofthethingsthatmakeStrutsuniquecomparedtootherframeworkslikeVelocity.

Note:

"

Thinkthin"

whenextendingtheActionclass.TheActionclassshouldcontroltheflowandnotthelogicoftheapplication.ByplacingthebusinesslogicinaseparatepackageorEJB,weallowflexibilityandreuse.

AnotherwayofthinkingaboutActionclassisastheAdapterdesignpattern.ThepurposeoftheActionisto"

Converttheinterfaceofaclassintoanotherinterfacetheclientsexpect.Adapterletsclassesworktogetherthatcouldn_totherwisebecauseofincompatibilityinterface"

(fromDesignPatterns-ElementsofReusableOOSoftwarebyGof).TheclientinthisinstanceistheActionServletthatknowsnothingaboutourspecificbusinessclassinterface.Therefore,Strutsprovidesabusinessinterfaceitdoesunderstand,Action.ByextendingtheAction,wemakeourbusinessinterfacecompatiblewithStrutsbusinessinterface.(AninterestingobservationisthatActionisaclassandnotaninterface.

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2