英文.docx

上传人:b****8 文档编号:9232250 上传时间:2023-05-17 格式:DOCX 页数:11 大小:68.63KB
下载 相关 举报
英文.docx_第1页
第1页 / 共11页
英文.docx_第2页
第2页 / 共11页
英文.docx_第3页
第3页 / 共11页
英文.docx_第4页
第4页 / 共11页
英文.docx_第5页
第5页 / 共11页
英文.docx_第6页
第6页 / 共11页
英文.docx_第7页
第7页 / 共11页
英文.docx_第8页
第8页 / 共11页
英文.docx_第9页
第9页 / 共11页
英文.docx_第10页
第10页 / 共11页
英文.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

英文.docx

《英文.docx》由会员分享,可在线阅读,更多相关《英文.docx(11页珍藏版)》请在冰点文库上搜索。

英文.docx

英文

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,made​​asemi-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,filltheformvalues​​totheform,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

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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