网上文件管理系统论文英文.docx
《网上文件管理系统论文英文.docx》由会员分享,可在线阅读,更多相关《网上文件管理系统论文英文.docx(15页珍藏版)》请在冰豆网上搜索。
![网上文件管理系统论文英文.docx](https://file1.bdocx.com/fileroot1/2023-2/2/1a2a9a1b-18a2-4061-ad41-d318438d53fc/1a2a9a1b-18a2-4061-ad41-d318438d53fc1.gif)
网上文件管理系统论文英文
ExploringtheStrutsarchitecture
Thisarticlecovers
_Introducingapplicationframeworks,MVC,andModel2
_UnderstandinghowStrutsworks
_UsingtheStrutscontrolflow
_ExploringthestrengthsandweaknessesofStruts
1Talkingthetalk
ThisarticleexplorestheStrutsframeworkindepthandhighlightsthebenefitsStrutscanbringtoyourdevelopmentefforts.Webelievethatonceyoucan“talkthetalk”ofwebarchitectureanddesign,youwillbebetterequippedtouseStrutswithyourownapplications.
WithasoundoverviewoftheStrutsarchitectureinplace,weoutlinetheStrutscontrolflowandthewayithandlestherequest-responseeventcycle.Agoodunderstandingofthisprocessmakesitmucheasiertocreateapplicationsthatmakethebestuseoftheframework.Choosingawebapplicationframeworkshouldnotbeacasualdecision.Manypeoplewillusethisbook,andespeciallythischapter,aspartofevaluatingStrutsfortheirproject.Accordingly,weconcludethischapterwithacandidlookatthestrengthsandweaknessesoftheStrutsframeworkandaddressconcernsregardingoverallperformance.Strutsisdesignedforprofessionaldevelopers.Tomake
informeddecisions,professionalsneedtobeawareofbothatool’scapabilitiesanditslimitations.
2WhyweneedStruts
Today’swebapplicationsarecriticalcomponentsofthecorporatemission.Asalways,developmentteamsneedtobuildapplicationsinrecordtime,buttheyhavetobuildthemrightandbuildthemtolast.Javawebdevelopersalreadyhaveutilitiesforbuildingpresentationpages,suchasJavaServerPagesandVelocitytemplates.Wealsohavemechanismsforhandling
databases—JDBCandEnterpriseJavaBeans(EJBs),forexample.Butwhatdoweusetoputthesecomponentstogether?
Wehavetheplumbingandthedrywall…whatelsedoweneed?
2.1Onestepback,threestepsforward
Inthelate1970s,whengraphicaluserinterfaces(GUIs)werebeinginvented,softwarearchitectssawapplicationsashavingthreemajorparts:
thepartthatWhyweneedStruts31managesdata,thepartthatcreatesscreensandreports,andthepartthathandlesinteractionsbetweentheuserandtheothersubsystems[Ooram].Intheearly1980s,theObjectWorks/Smalltalkprogrammingenvironmentintroducedthistriumvirateasadevelopmentframework.InSmalltalk80parlance,thedatasystemisdubbedtheModel,thepresentationsystemiscalledtheView,andtheinteractionsystemistheController.Manymoderndevelopmentenvironments,includingJava’sSwing,usethisModel/View/Controller(MVC)architecture(seefigure2.1)asthefoundationoftheirownframeworks.Javawebdevelopersalreadyhavecapabletools,suchasJDBCandJSP,forconsultingtheModelandcreatingtheView,butwhere’stheControllerforourwebapplications?
2.2EnterStruts
ThecenterpieceofStrutsisanMVC-styleController.TheStrutsControllerbridgesthegapbetweenModelandView.Theframeworkalsoincludesothermissingpiecesdevelopersneedtowritescalable,leading-edgewebapplications.Strutsisacollectionof“invisibleunderpinnings”thathelpdevelopersturnrawmaterialslikedatabasesandwebpagesintoacoherentapplication.
2.3Strutscontrollercomponents
TheStrutscontrollerisasetofprogrammablecomponentsthatallowdeveloperstodefineexactlyhowtheirapplicationinteractswiththeuser.Thesecomponentshidenasty,cumbersomeimplementationdetailsbehindlogicalnames.Developerscanprogramthesedetailsonce,thengobacktothinkingintermsofwhattheprogramdoesratherthanhowitdoesit.UsersinteractwithawebapplicationthroughhyperlinksandHTMLforms.Thehyperlinksleadtopagesthatdisplaydataandotherelements,suchastextandimages.Theformsgenerallysubmitdatatotheapplicationviasometypeofcustomaction.Asshowninfigure2.2,Strutsprovidescomponentsthatprogrammerscanusetodefinethehyperlinks,forms,andcustomactionsthatwebapplicationsusetointeractwiththeuser.Weusedthesecomponentstobuildastarterapplicationinchapter1.Inchapter3,wewalkthroughusingthesecomponentstobuildanothersimpleapplication.Then,inchapter4,weprovideadetailedoverviewofconfiguringthesecomponents.Laterchaptersprovidemoredetailaboutputtingeachcomponenttousewithinyourapplication.Inpart4wedemonstrateusingthecomponentsinthecontextofworkingapplications.But,sincethischapteristhearchitecturaloverview,let’sgoaheadandintroducethemajorStrutscomponentsnow.NOTETheStrutscomponentsareconfiguredviaXML.
Hyperlinks
Totheapplicationdeveloper,ahyperlinkisapathtosomeresourceintheapplication.Thismaybeawebpageoracustomaction.Itmayalsoincludespecialparameters.InStruts,developerscandefineahyperlinkasanActionForward.Theseobjectshavealogicalnameandapathproperty.ThisletsdeveloperssetthepathandthenrefertotheActionForwardbyname.ActionForwardsareusuallydefinedinanXMLconfigurationfilethatStrutsreadswhenthewebapplicationloads.StrutsusestheXMLdefinitionstocreatetheStrutsconfiguration,whichincludesalistofActionForwards.TheXMLelementthatwouldcreateanActionForwardforawelcomehyperlinkmightlooklikethis:
name="welcome"
path="/pages/index.jsp"/>
ThiselementwouldcreateanActionFormJavaBeanwithitsnamepropertysettowelcomeanditspathpropertysetto/pages/index.jsp.JSPpagesandothercomponentscanthenrefertothewelcomeforward.TheStrutsframeworkwilllookupthewelcomeActionForwardbeanandretrievethepathtocompletethehyperlink.Thisallowsdeveloperstochangethedestination
ofalinkwithoutchangingallthecomponentsthatrefertothatlink.Inmostwebapplications,detailslikethisarehardcodedintoJSPandJavacode,makingchangesdifficultandpronetoerror.InaStrutsapplication,thesedetailscanbechangedthroughouttheapplicationwithouttouchingasinglepageorJavaclass.FormoreaboutActionForwards,seechapter6.
HTMLforms
Thewebprotocols,HTTPandHTML,provideamechanismforsubmittingdata
fromaformbutleavereceivingthedataasanexerciseforthedeveloper.TheStrutsframeworkprovidesanActionFormclass,whichisdesignedtohandleinputfromanHTMLform,validatetheinput,andredisplaytheformtotheuserforcorrection(whenneeded),alongwithanycorrespondingpromptsormessages.ActionFormsarejustJavaBeanswithacoupleofstandardmethodstomanagethevalidationandrevisioncycle.StrutsautomaticallymatchestheJavaBeanpropertieswiththeattributesoftheHTMLcontrols.ThedeveloperdefinestheAction-Formclass.Strutsdoestherest.Thisclasswillautomaticallypopulatetheusernamefieldfromaformwithan
HTMLformelementofthesamename,asshownhere:
publicfinalclassLogonFormextendsActionForm{
privateStringusername=null;
publicStringgetUsername(){
return(this.username);
}
publicvoidsetUsername(Stringusername){
this.username=username;
}
}
Otherpropertieswouldbeaddedforeachfieldoftheform.ThisletsothercomponentsgetwhattheyneedfromastandardJavaBean,soeveryonedoesnothavetosiftthroughanHTTPrequest.TheActionFormclassesarecreatedusingnormalJavaclasses.TheStrutsconfiguration
referstotheActionFormclassesthroughasetofdescriptors:
theandelements.TheelementsaredescriptorsthattheframeworkusestoidentifyandinstantiatetheActionFormobjects,asshownhere:
name="articleForm"
type="org.apache.artimus.struts.Form"/>
TheStrutsconfigurationliststheActionFormbeansitusesandgivestheAction-Formclassesalogicalnametousewithintheapplication.1.0vs1.1InStruts1.1theActionFormcanalsouseaMap(java.util.Map)tostoretheattributenamesratherthandefineindividualproperties.AnewtypeofJavaBean,theDynaBean,canalsobeusedwithStruts1.1andlater.YoucanspecifythepropertiesforaDynaActionFormbyusinganXMLelement.Ineffect,thisdoesletyoudefineActionFormsintheStrutsconfigurationfile.
Customactions
AnHTMLformusesanactionparametertotellthebrowserwheretosendtheform’sdata.TheStrutsframeworksuppliesacorrespondingActionclasstoreceivesuchdata.Theframeworkautomaticallycreates,populates,validates,andfinallypassestheappropriateActionFormtotheActionobject.TheActioncanthengetthedataitneedsdirectlyfromtheActionFormbean.Here’sanexample:
publicfinalclassLogonActionextendsAction{
publicActionForwardperform(ActionMappingmapping,
ActionFormform,
HttpServletRequestrequest,
HttpServletResponseresponse)
throwsIOException,ServletException{
MyFormmyForm=(MyForm)form;
//...
returnmapping.findForward("continue");
}
}
AnActionconcludesbyreturninganActionForwardobjecttothecontroller.ThisallowstheActiontochooseadefinitionusinglogicalnames,likecontinueorcancel,ratherthansystempaths.
Toensureextensibility,thecontrolleralsopassesthecurrentrequestandresponseobject.Inpractice,anActioncandoanythingaJavaServletcando.
InadditiontotheActionForward,ActionForm,andActionobjects,theStrutscontrollerlayerprovidesseveralotherspecializedcomponents,includingAction-MappingsandtheActionServlet.Strutsalsosupportslocalizingyourapplicationfromthecontrollerlayer.
ActionMappings
Inawebapplication,everyresourcemustbereferredtothroughaUniformResourceIdentifier(URI).ThisincludesHTMLpages,JSPpages,andanycustomactions.TogivethecustomActionsaURI,orpath,theStrutsframeworkprovidesanActionMappingobject.LiketheActionForwardsandActionForms,themappingsareusually