信息科学与工程学院毕业设计科技文献翻译Word下载.docx

上传人:b****6 文档编号:16550818 上传时间:2022-11-24 格式:DOCX 页数:10 大小:60.03KB
下载 相关 举报
信息科学与工程学院毕业设计科技文献翻译Word下载.docx_第1页
第1页 / 共10页
信息科学与工程学院毕业设计科技文献翻译Word下载.docx_第2页
第2页 / 共10页
信息科学与工程学院毕业设计科技文献翻译Word下载.docx_第3页
第3页 / 共10页
信息科学与工程学院毕业设计科技文献翻译Word下载.docx_第4页
第4页 / 共10页
信息科学与工程学院毕业设计科技文献翻译Word下载.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

信息科学与工程学院毕业设计科技文献翻译Word下载.docx

《信息科学与工程学院毕业设计科技文献翻译Word下载.docx》由会员分享,可在线阅读,更多相关《信息科学与工程学院毕业设计科技文献翻译Word下载.docx(10页珍藏版)》请在冰豆网上搜索。

信息科学与工程学院毕业设计科技文献翻译Word下载.docx

专业计算机科学与技术 

指导教师李双双   

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.

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

当前位置:首页 > 小学教育 > 语文

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

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