计算机专业文献翻译Jsp最佳实践Word格式.docx
- 文档编号:21146634
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:8
- 大小:23.08KB
计算机专业文献翻译Jsp最佳实践Word格式.docx
《计算机专业文献翻译Jsp最佳实践Word格式.docx》由会员分享,可在线阅读,更多相关《计算机专业文献翻译Jsp最佳实践Word格式.docx(8页珍藏版)》请在冰豆网上搜索。
1.SeparateHTMLfromJava
2.PlacebusinesslogicinJavaBeans
3.Factorgeneralbehavioroutofcustomtaghandlerclasses
4.FavorHTMLinJavahandlerclassesoverJavainJSPs
5.Useanappropriateinclusionmechanism
6.UseaJSPtemplatemechanism
7.Usestylesheets
8.UsetheMVCpattern
9.Useavailablecustomtaglibraries
10.UseJSPcommentsinmostcases
11.FollowHTMLbestpractices
12.UtilizetheJSPexceptionmechanism
ThesetipswillhelpyouwriteJSPsthatarereusableandeasytomaintain.
(1)SeparateHTMLfromJava
ItcanbetemptingtothrowallJavaandHTMLcodenecessaryforaWebpageintoasingleJSPfile.Insimplesystemdevelopment,suchanapproachmakesiteasyforsomeonenewtothesystemtolocateallrelevantcodeinoneplaceandunderstandhowitallinteracts.However,thisapproachbecomesburdensomeandcostlywhentheapplicationgrowsmorecomplexandmoredevelopersbecomeinvolved.
CombiningHTMLandJavainthesamesourcecodecanmakethecodesignificantlylessreadable.Toenhancesoftwarereadability,developersoftenuseindentation;
butmixingHTMLandJavascriptletsinthesamefilecanmakeusefulindentationextremelydifficulttomaintain.
ManyWebdevelopmentmethodologiesandarchitecturesnowemphasizetheseparationofHTMLfromJavacodesodifferentdeveloperscanfocusontheirstrengths.ProperlyseparatingJavaandHTML,includingHTML-likeJSPtagsandcustomtags,allowsWebdesignersandHTMLcoderstoworkontheHTML(presentation)aspects,whileJavadevelopersworkontheapplication′sJava(processinglogic)portions.Javadevelopersfocusonbusinesslogicastheyimplementthebehaviorbehindthecustomtags;
WebdesignersthenusethesecustomtagsjustastheyuseordinaryHTMLtags.
(2)PlacebusinesslogicinJavaBeans
JavacodeincludeddirectlyinsideaJSPisnotasreadilyaccessibletootherJSPsasJavacodecontainedwithinaJavaBean.CommonbehaviorandbusinesslogicplacedinJavaBeanscannotonlybeusedbyotherJSPsbutalsobyotherportionsoftheapplication.ThatisbecauseJavaBeansaremerelyJavaclassesthatsatisfysomebasicconventions(suchasaconstructorwithnoargumentsandpublicget/setmethodsforprivatedatamembers)andcanbeusedasanyotherJavaclass.NotethatEnterpriseJavaBeans(EJBs)arealsousefulforstoringbehaviorsanddatacommontoallcomponentsoftheapplication.
(3)Factorgeneralbehavioroutofcustomtaghandlerclasses
Javaclassesknownascustomtaghandlersimplementcustomtags.UnlikeJavaBeans,customtaghandlerclassesarenotreadilyusedlikeordinaryJavautilityclasses.Instead,customtaghandlerclassesimplementspecificinterfaces--orextendclassesthatprovidetheseinterfaces′basicimplementations.BecausetheyarenotreadilyreusedoutsideJSPs,customtaghandlersshouldcontainonlyspecificbehaviorthatwouldnotbeusefuloutsidethatcustomtag--thatis,outsidetheJSP.CustomtagsoftenrequiresupportforcommonbehaviorsorbusinesslogicandcanutilizeJavaBeansorEJBsthatperformthosecommonbehaviors.
(4)FavorHTMLinJavahandlerclassesoverJavainJSPs
SometimescleanlyseparatingHTML,JSPtags,andHTML-likecustomtagsfromJavarequiresunnecessarilyconvolutedcode.Inthesecases,youeitherincludeJavascriptletsandexpressionsintheJSPorputsomeHTMLcodeintheJavataghandlerclass.
I′dratherseeasmallamountofHTMLcodeintheJavaclassthanseeJava,suchasscriptletsandexpressions,intheJSP.Sincecustomtaghandlersarespecifictothecustomtagstheyimplement(andnotreusableoutsideJSPs),placingnecessaryHTMLthereisnottroublesome.Sun′sJava2Platform,EnterpriseEdition(J2EE)Blueprintsdocumentationdiscussesthisissuefurther.
(5)Useanappropriateinclusionmechanism
Itisrarelygooddesigntoreproducecodecommonlyusedbydifferentapplicationpieceseachtimeanotherpieceofthatapplicationneedsthatfunctionality.FactoringcommonJSPorHTMLcodeoutofmultiplepagesandintoasinglefileimprovesmaintainability(youneedtomakechangesinonlyonelocation)andreusability.
TwoJSPincludemechanismsreducecoderedundancyandpromotereusability;
toensurethatyouusetheappropriateincludemechanism,itisimportanttoknowthedifferencesbetweenthetwo.Generally,IusetheincludedirectiveunlessIcanjustifyaneedfortheincludeaction.Question7intheBlueprints′"
WebTier"
sectionprovidesagoodresourceforunderstandingthedifferencesbetweenthetwoincludemechanismsanddeterminingwhichtouseinaparticularsituation.
(6)UseaJSPtemplatemechanism
AtemplatemechanismallowsforacommonfiletocontrolWebpage,orJSP,layout.Then,whenyouwanttochangethelayout,youneedtomodifyonlyonefile,andalltheotherpageswillreflectthelayoutchange.Thisdoesn′tjustmakeformoremaintainablecode;
usingtemplatestocontrollayoutalsomakesWebpagesmoreaestheticallypleasingtouserswhoseeconsistentlayoutsforallanapplication′spages.
(7)Usestylesheets
Justastemplatesenabledeveloperstoplacelayoutcontrolinasinglelocation,stylesheetsenabledeveloperstoplaceappearancecontrolinasinglelocation.IuseCascadingStyleSheets(CSS)tocontrolsuchitemsasfontfamilies,fontsizes,andtablecharacteristics.Liketemplates,stylesheetsallowthedevelopertomakechangesinonelocation;
thosechangesimmediatelyreflectonallappropriatepages,resultinginincreasedmaintainabilityandconsistentappearancetousers.
(8)UsetheMVCpattern
WhileotherdesignpatternscanbeusedeffectivelywithJSPs,IoftenusetheModel-View-Controller(MVC)architecturewithJSPtechnology.MVCenablesthedevelopmentofapplicationsthatareeasiertocreate,test,maintain,andenhance.InJSPterminology,implementationofanMVCarchitectureisoftenreferredtoasModel2(fromanearlyJSPspecification).TheJ2EEBlueprintssamplesarebasedonMVC.
(9)Useavailablecustomtaglibraries
Whyshoulddevelopersspendtimereinventingthewheelandworryingabouttestinganddebuggingwhencustomtaglibrariesarereadilyavailableformanydifferentpurposes?
Somevendorsprovidecustomtaglibrariestotheircustomersforfreeorforindividualpurchase,butmanycustomtagscanbefoundonline.Resourcesprovidesagoodstartingpointforlocatingpotentiallyusefultaglibraries.
Whilethesethird-partycustomtaglibrariesoccasionallyhavebugs,mostlikelysuchproblemswillbediscovered,sincemanydevelopersusetheselibrariesandtestthemintheirownapplications.Also,manycustomtagsareopensource,soyoucaneditthemtomeetyourneeds.
Ifinditwellworthmytimetokeepinformedofavailablecustomtags,sincetheselibrariesoftenprovidefunctionalitycommontomostWebapplications.Whilelearningaboutavailablecustomtaglibrariesrequiresasmalltimeinvestment,reusingalready-availablecustomtagssavesthetimeofwriting,testing,anddebuggingmyowncustomtags.Asmentionedabove,manytaglibrariesarealsoopensource;
inthesecases,Icanreadilyadaptgeneralbehaviortomyspecificproject′ssituation.
(10)UseJSPcommentsinmostcases
Appropriatecommentingseemstochallengesoftwaredevelopers.JSPs,likeothertypesofcode,shouldincludecommentsthatdescribecomplexorextraordinaryfunctionality,thepages′purpose,andothergeneralinformationtypicallycommentedoutinsourcecode.
SinceJSPsallowdeveloperstointermixJava,JSPtags,andHTMLtagsinthesamepage,therearemultiplewaystocommentaJSPpage.Developersshouldcarefullyconsiderwhichtypeofcommenttoemployinthepage.HTMLcommentswillbeviewableinthecompiledJSP′sHTMLsourcecode,andbothmajorbrowsersmakeviewingthissourceeasy.JSPcomments,ontheotherhand,arenotplacedintheHTMLdocumentcreatedbytheJSPcompilationprocess.Thesecommentscannotbeviewedaspartofthepage′ssourcethroughthebrowser,andtheydonotincreasethesizeoftherenderedpage′sgeneratedsource.JavacommentscanalsooccurinaJSPinsideJavascriptletsections.Thesearenotviewableinthebrowsereither,butincludingJavacommentsintheJSPpageviolatestheprincipleofseparatingJavafromtheHTML.
Codecommentsareusuallymeantfordeveloperswhowriteandmaintaincode.Therefore,useJSPcommentsunlessthereisacompellingreasontohavethecommentsdisplayinthebrowseruponrequest.
(11)FollowHTMLbestpractices
WhenJavaisfactoredoutoftheJSPandintoJavaBeansandcustomtaghandlers,theJSPconsistsmostlyofJSPtags,includingcustomtags,andHTMLtags.TomaketheJSPeasiertounderstandandmaintain,followbestpracticesrelatedtoHTMLdevelopment.
(12)UtilizetheJSPexceptionmechanism
Whileathrownexception′sstacktraceprovesextremelyusefulfordeveloperswhendebuggingtheircode,itisrarelydesirabletoshareanentireexceptionstack
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机专业 文献 翻译 Jsp 最佳 实践