网上文件管理系统论文英文.docx

上传人:b****7 文档编号:9041990 上传时间:2023-02-02 格式:DOCX 页数:15 大小:29.61KB
下载 相关 举报
网上文件管理系统论文英文.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

网上文件管理系统论文英文

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

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

当前位置:首页 > 高等教育 > 农学

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

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