英文.docx
- 文档编号:9232250
- 上传时间:2023-05-17
- 格式:DOCX
- 页数:11
- 大小:68.63KB
英文.docx
《英文.docx》由会员分享,可在线阅读,更多相关《英文.docx(11页珍藏版)》请在冰点文库上搜索。
英文
Abstract
KidsingradeschoolputHTMLpagesontheInternet.However,thereisamonumentaldifferencebetweenagradeschoolpageandaprofessionallydevelopedWebsite.Thepagedesigner(orHTMLdeveloper)mustunderstandcolors,thecustomer,productflow,pagelayout,browsercompatibility,imagecreation,JavaScript,andmore.Puttingagreatlookingsitetogethertakesalotofwork,andmostJavadevelopersaremoreinterestedincreatingagreatlookingobjectinterfacethanauserinterface.JavaServerPages(JSP)technologyprovidesthegluebetweenthepagedesignerandtheJavadeveloper.
Ifyouhaveworkedonalarge-scaleWebapplication,youunderstandthetermchange.Model-View-Controller(MVC)isadesignpatternputtogethertohelpcontrolchange.MVCdecouplesinterfacefrombusinesslogicanddata.StrutsisanMVCimplementationthatusesServlets2.2andJSP1.1tags,fromtheJ2EEspecifications,aspartoftheimplementation.YoumayneverimplementasystemwithStruts,butlookingatStrutsmaygiveyousomeideasonyourfutureServletsandJSPimplementations.oucarefullystudytherealapplication,youwillfindtheprogramgenerallycomposedoftwodifferenttypesofcomponents,andprocedurestodealwithspecificmattersarecloselyrelated,wemightcallthembusinesscomponents;otherapplicationservices.Forexample:
ataxcollectionsystemandalibrarymanagementsystemthereisabigdifferenceinhandlingtheirbusiness,dealdirectlywiththebusinesscomponentsduetothedifferentnatureofthebusinessisunlikelytobereusedindifferentsystems,whileotherscomponentssuchastheseonlyrelatedtotheprogramcomponentoftheprogramflowofcontrol,inputvalidation,errorhandlingandtaglibraryinthedifferentsystemscanbereused.Peoplewillnaturallywanttoextractthesedifferentapplicationshaveincommonsomethingsout,madeasemi-finishedprogram,thissemi-finishedproductsistheso-calledproceduralframeworktodoanewthingwhentheydonothavetostartfromscratch,butcanbegantobuildonthisfoundation.Infact,somelargesoftwarecompanieshavechosentobuildsuchaframework.Butmostsmallandmedium-sizedsoftwarecompaniesorotherorganizations,therearenoconditionstoestablishaframework.Strutsasanopensourceapplicationframework,inrecentyearshasbeenrapiddevelopmentofveryextensiveapplicationinJSPWebapplicationdevelopment,someoftheliteraturethatithasbecomethedefactostandardoftheJSPWebapplicationframework.
Keywords:
Internet,Struts,interface,implementation
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.
MVCModel
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,alsocommonlyknownasMVCModelorMVC2.
Figure4.MVCModel2
Struts,anMVCimplementation
Strutsisasetofcooperatingclasses,servlets,andJSPtagsthatmakeupareusableMVC2design.ThisdefinitionimpliesthatStrutsisaframework,ratherthanalibrary,butStrutsalsocontainsanextensivetaglibraryandutilityclassesthatworkindependentlyoftheframework.Figure5displaysanoverviewofStruts.
Figure5.Strutsoverview
StrutsIntroductionanddetails
Introduction
∙Clientbrowser
AnHTTPrequestfromtheclientbrowsercreatesanevent.TheWebcontainerwillrespondwithanHTTPresponse.
∙Controller
TheControllerreceivestherequestfromthebrowser,andmakesthedecisionwheretosendtherequest.WithStruts,theControllerisacommanddesignpatternimplementedasaservlet.Thestruts-config.xmlfileconfigurestheController.
∙Businesslogic
Thebusinesslogicupdatesthestateofthemodelandhelpscontroltheflowoftheapplication.WithStrutsthisisdonewithanActionclassasathinwrappertotheactualbusinesslogic.
∙Modelstate
Themodelrepresentsthestateoftheapplication.Thebusinessobjectsupdatetheapplicationstate.ActionFormbeanrepresentstheModelstateatasessionorrequestlevel,andnotatapersistentlevel.TheJSPfilereadsinformationfromtheActionFormbeanusingJSPtags.
∙View
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.Actionstartedasaninterfaceandchangedintoaclassovertime.Nothing'sperfect.)
Process
Entertheusernamepasswordsubmittheformsubmittedtotheactionattributeoflogin.actionactionunderthepathattributetofind,theActionServletreadstruts-config.xmlfiletofindaction,bythenameattributetofindthenameoftheform-beansform-beanpropertypackagenameoftheActionFormclassname,thefirstinstanceoftheform,filltheformvaluestotheform,calltheform'svalidatemethodvalidation,theActionErrorsreturnnulltorepresentverificationthrough,orfailuretoreturntheinputspecifiedpage.verifiedbytheinstantiationaction,theimplementationoftheActionexecutemethod.
details
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,IamsayingActio
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 英文