信息科学与工程学院毕业设计科技文献翻译.docx
- 文档编号:3645925
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:10
- 大小:60.03KB
信息科学与工程学院毕业设计科技文献翻译.docx
《信息科学与工程学院毕业设计科技文献翻译.docx》由会员分享,可在线阅读,更多相关《信息科学与工程学院毕业设计科技文献翻译.docx(10页珍藏版)》请在冰豆网上搜索。
信息科学与工程学院毕业设计科技文献翻译
信息科学与工程学院毕业设计科技文献翻译
《Struts——AnOpen-sourceMVCImplementation》
《Struts——一种开源MVC的实现》
姓名张三丰
学号20140000
年级2014级
专业计算机科学与技术
指导教师李双双
2018年3月
Struts——AnOpen-sourceMVCImplementation
ThisarticleintroducesStruts,aModel-View-ControllerimplementationthatusesservletsandJavaServerPages(JSP)technology.StrutscanhelpyoucontrolchangeinyourWebprojectandpromotespecialization.EvenifyouneverimplementasystemwithStruts,youmaygetsomeideasforyourfutureservletsandJSPpageimplementation
1.Introduction
Ifyouhaveworkedonalarge-scaleWebapplication,youunderstandthetermchange.Model-View-Controller(MVC)isadesignpatternputtogethertohelpcontrolchange.MVCdecouplesinterfacefrombusinesslogicanddata.StrutsisanMVCimplementationthatusesServlets2.2andJSP1.1tags,fromtheJ2EEspecifications,aspartoftheimplementation.YoumayneverimplementasystemwithStruts,butlookingatStrutsmaygiveyousomeideasonyourfutureServletsandJSPimplementations.
2.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.
3.StrutsSummary
3.1Strutsdetails
DisplayedinFigure1isastripped-downUMLdiagramoftheorg.apache.Struts.actionpackage.Figure6showstheminimalrelationshipsamongActionServlet(Controller),ActionForm(FormState),andAction(ModelWrapper).
Figure1UMLdiagramoftherelationshipoftheCommand(ActionServlet)totheModel(Action&ActionForm)
3.1.1TheActionServletclass
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:
1)ThepagedesignerdoesnothavetowadethroughJavacodetounderstandtheflowoftheapplication.
2)TheJavadeveloperdoesnotneedtorecompilecodewhenmakingflowchanges.
3)CommandfunctionalitycanbeaddedbyextendingActionServlet.
3.1.2TheActionFormclass
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.
3.1.3TheActionclass
TheActionclassisawrapperaroundthebusinesslogic.ThepurposeofActionclassistotranslatetheHttpServletRequesttothebusinesslogic.TouseAction,subclassandoverwritetheprocess()method.
TheActionServlet(Command)passestheparameterizedclassestoActionFormusingtheperform()method.Again,nomoredreadfulrequest.getParameter()calls.Bythetimetheeventgetshere,theinputformdata(orHTMLformdata)hasalreadybeentranslatedoutoftherequeststreamandintoanActionFormclass.
3.1.4TheErrorclasses
ActionErrorencapsulatesanindividualerrormessage.ActionErrorsisacontainerofActionErrorclassesthattheViewcanaccessusingtags.ActionErrorsisStrutswayofkeepingupwithalistoferrors.
Figure2UMLdiagramoftherelationshipoftheCommand(ActionServlet)totheModel(Action)
3.1.5TheActionMappingclass
AnincomingeventisnormallyintheformofanHTTPrequest,whichtheservletContainerturnsintoanHttpServletRequest.TheControllerlooksattheincomingeventanddispatchestherequesttoanActionclass.TheStruts-config.xmldetermineswhatActionclasstheControllercalls.TheStruts-config.xmlconfigurationinformationistranslatedintoasetofActionMapping,whichareputintocontainerofActionMappings.(Ifyouhavenotnoticedit,classesthatendwithsarecontainers)
TheActionMappingcontainstheknowledgeofhowaspecificeventmapstospecificActions.TheActionServlet(Command)passestheActionMappingtotheActionclassviatheperform()method.ThisallowsActiontoaccesstheinformationtocontrolflow.
3.2Strutspros
3.2.1UseofJSPtagmechanism
ThetagfeaturepromotesreusablecodeandabstractsJavacodefromtheJSPfile.ThisfeatureallowsniceintegrationintoJSP-baseddevelopmenttoolsthatallowauthoringwithtags.
3.2.2Taglibrary
Whyre-inventthewheel,orataglibrary?
Ifyoucannotfindsomethingyouneedinthelibrary,contribute.Inaddition,StrutsprovidesastartingpointifyouarelearningJSPtagtechnology.
3.2.3Opensource
Youhavealltheadvantagesofopensource,suchasbeingabletoseethecodeandhavingeveryoneelseusingthelibraryreviewingthecode.Manyeyesmakeforgreatcodereview.
3.2.4SampleMVCimplementation
StrutsofferssomeinsightifyouwanttocreateyourownMVCimplementation.
3.2.5Managetheproblemspace
Divideandconquerisanicewayofsolvingtheproblemandmakingtheproblemmanageable.Ofcourse,theswordcutsbothways.Theproblemismorecomplexandneedsmoremanagement.
3.3Strutscons
3.3.1Youth
Strutsdevelopmentisstillinpreliminaryform.Theyareworkingtowardreleasingaversion1.0,butaswithany1.0version,itdoesnotprovideallthebellsandwhistles.
3.3.2Change
Theframeworkisundergoingarapidamountofchange.AgreatdealofchangehasoccurredbetweenStruts0.5and1.0.YoumaywanttodownloadthemostcurrentStrutsnightlydistributions,toavoiddeprecatedmethods.Inthelast6months,IhaveseentheStrutslibrarygrowfrom90Ktoover270K.IhadtomodifymyexamplesseveraltimesbecauseofchangesinStruts,andIamnotgoingtoguaranteemyexampleswillworkwiththeversionofStrutsyoudownload.
3.3.3Correctlevelofabstraction
DoesStrutsprovidethecorrectlevelofabstraction?
Whatistheproperlevelofabstractionforthepagedesigner?
Thatisthe$64Kquestion.ShouldweallowapagedesigneraccesstoJavacodeinpagedevelopment?
SomeframeworkslikeVelocitysayno,andprovideyetanotherlanguagetolearnforWebdevelopment.ThereissomevaliditytolimitingJavacodeaccessinUIdevelopment.Mostimportantly,giveapagedesigneralittlebitofJava,andhewillusealotofJava.IsawthishappenallthetimeinMicrosoftASPdevelopment.InASPdevelopment,youweresupposedtocreateCOMobjectsandthenwritealittleASPscripttoglueitalltogether.Instead,theASPdeveloperswouldgocrazywithASPscript.
3.3.4Limitedscope
StrutsisaWeb-basedMVCsolutionthatismeantbeimplementedwithHTML,JSPfiles,andservlets.
3.3.5J2EEapplicationsupport
StrutsrequiresaservletcontainerthatsupportsJSP1.1andServlet2.2specifications.Thisalonewillnotsolveallyourinstallissues,unlessyouareusingTomcat3.2.IhavehadagreatdealofproblemsinstallingthelibrarywithNetscapeiPlanet6.0,whichissupposedlythefirstJ2EE-compliantapplicationserver.IrecommendvisitingtheStrutsUserMailingListarchive(seeResources)whenyourunintoproblems.
3.3.6Complexity
Separatingtheproblemintopartsintroducescomplexity.ThereisnoquestionthatsomeeducationwillhavetogoontounderstandStruts.Withtheconstantchangesoccurring,thiscanbefrustratingattimes.WelcometotheWeb.
4.FutureofStruts
Thingschangerapidlyinthisnewageofsoftwaredevelopment.Inlessthan5years,Ihaveseenthingsgofromcgi/perl,toISAPI/NSAPI,toASPwithVB,andnowJavaandJ2EE.SunisworkinghardtoadaptchangestotheJSP/servletarchitecture,justastheyhaveinthepastwiththeJavalanguageandAPI.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 信息科学 工程学院 毕业设计 科技 文献 翻译
![提示](https://static.bdocx.com/images/bang_tan.gif)