网络工程专业毕业外文翻译.docx

上传人:b****5 文档编号:4486197 上传时间:2022-12-01 格式:DOCX 页数:15 大小:236.73KB
下载 相关 举报
网络工程专业毕业外文翻译.docx_第1页
第1页 / 共15页
网络工程专业毕业外文翻译.docx_第2页
第2页 / 共15页
网络工程专业毕业外文翻译.docx_第3页
第3页 / 共15页
网络工程专业毕业外文翻译.docx_第4页
第4页 / 共15页
网络工程专业毕业外文翻译.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

网络工程专业毕业外文翻译.docx

《网络工程专业毕业外文翻译.docx》由会员分享,可在线阅读,更多相关《网络工程专业毕业外文翻译.docx(15页珍藏版)》请在冰豆网上搜索。

网络工程专业毕业外文翻译.docx

网络工程专业毕业外文翻译

XX大学

毕业设计(论文)说明书

英文翻译

专业

网络工程

班级

网X

姓名

X

学号

X

指导教师

X

 

二O一五年六月十七日

外文原文

出自《IBMSystemJournal.2014》作者:

MalcolmDavis

Struts——AnOpen-sourceMVCImplementation

ThisarticleintroducesStruts,aModel-View-ControllerimplementationthatusesservletsandJavaServerPages(JSP)technology.StrutscanhelpyoucontrolchangeinyourWebprojectandpromotespecialization.EvenifyouneverimplementasystemwithStruts,youmaygetsomeideasforyourfutureservletsandJSPpageimplementation.

Introduction

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.

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.

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.(

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

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1