外文翻譯-外文資料和譯文_第1頁(yè)
外文翻譯-外文資料和譯文_第2頁(yè)
外文翻譯-外文資料和譯文_第3頁(yè)
外文翻譯-外文資料和譯文_第4頁(yè)
外文翻譯-外文資料和譯文_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

XX大學(xué)XXXXXXX外文資料和譯文專業(yè):軟件工程班級(jí):軟件XXXXX姓名:XXXXX學(xué)號(hào):XXXXXXXXXXXXXX指導(dǎo)教師:XXXXXXXX2009年12月17日原文AJSPtechnologyoverviewLet'sbeginbytalkingalittleabouthowJSPpageswork.We'regoingtokeepitsimpleandfocusonsomeofthebasics.Formoreinformation,seeResourcesforlinkstoadditionalJSPtechnologyinformation.Inthetraditionalsense,JSPpageslookverymuchlikeHTMLpages,withafewextratags.ThesetagsallowthedesignertoembedJavacode(notJavaScript)inthepageitself.AWebapplicationserver,liketheIBMWebSphereApplicationServer,willinterceptrequestsforJSPpages.It'stippedofftotheirexistencebythepage'sextension:.jsp(not.html).TheWebapplicationserverthenpreprocessestheJSPpage,takingouttheJSPtagsandanyembeddedJavacode,leavingonlytheHTML.TheextractedJSPtagsandembeddedJavacodeareusedtobuildaJavaservlet(JSPpageservlet)thatrunsthecodeandinsertstheresultsbackintotheoriginalpagewheretheJSPtagsusedtobe.TheresultispureHTML.TheJavaisstrippedoutandrunontheserverbeforetherequestingbrowserseesanyresult.WecanapplythesameprincipletoanXMLpage.BeforetherequesteroftheJSPpagecontainingXMLeverseestheXML(beitabrowserorsomeotherB2Bapplication),theJavacodeisstrippedoutoftheJSPpageandusedtogenerateadditionalcontent,whichisinsertedbackintothepageatthepointswheretheJSPtagsusedtoreside.Thisfeaturegivesyoutheabilitytocontrolexactlywherenewcontentistobeinserted,downtothecharacter.We'lllookathowtomakethisworkinaminute.First,let'sconsiderwhyyoumightwanttocreatedynamicXMLusingJSP.WhynotsimplywriteaJavaapplicationorservlettogeneratetheentiredocumentWhybotherwithJSPatallThemostimportantreason,providingonlyportionsofanXMLdocumentaredynamic,isthatitmakessensenottoregeneratethatstaticcontentforeveryrequest.UsingaJSPpage,thestaticXMLwithinthepageactsasatemplatethatisfilledoutbythedynamiccontent.YourJavacodeistaskedwithgeneratingonlythecontentthatmightchangeovertime--amoreefficientapproach.Asapracticalmatter,JSPpagesallowyoutoseparatetasksforwhichdifferentdeveloperswillberesponsible.Inparticular,theyallowyoutobetterseparatethedatafromtheview,allowingyoutoaddnewpresentationswithoutaffectingthelogic.ImaginehavingoneJavaservletthatperformsthebusinesslogicandredirectstheresultingdatatoanappropriateJSPpagebasedonthenatureoftherequest.Forexample,aservletmightredirectdatatoaJSPpagecontainingWMLwhenitdetectsaWAPphonebrowsermakingtherequest.ItcouldalsoredirectthedatatoaJSPpagecontainingHTMLforstandardbrowserrequests.BenefitsofJSPJSPpagesaretranslatedintoservlets.So,fundamentally,anytaskJSPpagescanperformcouldalsobeaccomplishedbyservlets.However,thisunderlyingequivalencedoesnotmeanthatservletsandJSPpagesareequallyappropriateinallscenarios.Theissueisnotthepowerofthetechnology,itistheconvenience,productivity,andmaintainabilityofoneortheother.Afterall,anythingyoucandoonaparticularcomputerplatformintheJavaprogramminglanguageyoucouldalsodoinassemblylanguage.Butitstillmatterswhichyouchoose. JSPprovidesthefollowingbenefitsoverservletsalone:iseasiertowriteandmaintaintheHTML.YourstaticcodeisordinaryHTML:noextrabackslashes,nodoublequotes,andnolurkingJavacanusestandardWeb-sitedevelopmenttools.EvenHTMLtoolsthatknownothingaboutJSPcanbeusedbecausetheysimplyignoretheJSP.Youcandivideupyourdevelopmentteam.TheJavaprogrammerscanworkonthedynamiccode.TheWebdeveloperscanconcentrateonthepresentationlayer.Onlargeprojects,thisdivisionisveryimportant.Dependingonthesizeofyourteamandthecomplexityofyourproject,youcanenforceaweakerorstrongerseparationbetweenthestaticHTMLandthedynamic,thisdiscussionisnottosaythatyoushouldstopusingservletsanduseonlyJSPinstead.Bynomeans.Almostallprojectswilluseboth.Forsomerequestsinyourproject,youwilluseservlets.Forothers,youwilluseJSP.Forstillothers,youwillcombinethemwiththeMVCarchitecture.Youwanttheappropriatetoolforthejob,andservlets,bythemselves,donotcompleteyourtoolkit.AdvantagesofJSPOverCompetingTechnologiesAnumberofyearsago,Martywasinvitedtoattendasmall20-personindustryroundtablediscussiononsoftwaretechnology.SittingintheseatnexttoMartywasJamesGosling,inventoroftheJavaprogramminglanguage.Sittingseveralseatsawaywasahigh-levelmanagerfromaverylargesoftwarecompanyinRedmond,Washington.Duringthediscussion,themoderatorbroughtupthesubjectofJini,whichatthattimewasanewJavatechnology.Themoderatoraskedthemanagerwhathethoughtofit,andthemanagerrespondedthatitwastooearlytotell,butthatitseemedtobeanexcellentidea.Hewentontosaythattheywouldkeepaneyeonit,andifitseemedtobecatchingon,theywouldfollowhiscompany'susual"embraceandextend"strategy.Atthispoint,Goslinglightheartedlyinterjected"Youmeandisgraceanddistend." Now,thegrievancethatGoslingwasairingwasthathefeltthatthiscompanywouldtaketechnologyfromothercompaniesandsubornitfortheirownpurposes.ButguesswhatTheshoeisontheotherfoothere.TheJavacommunitydidnotinventtheideaofdesigningpagesasamixtureofstaticHTMLanddynamiccodemarkedwithspecialtags.Forexample,ColdFusiondidityearsearlier.EvenASP(aproductfromtheverysoftwarecompanyoftheaforementionedmanager)popularizedthisapproachbeforeJSPcamealonganddecidedtojumponthebandwagon.Infact,JSPnotonlyadoptedthegeneralidea,itevenusedmanyofthesamespecialtagsasASPdid. So,thequestionbecomes:whyuseJSPinsteadofoneoftheseothertechnologiesOurfirstresponseisthatwearenotarguingthateveryoneshould.Severalofthoseothertechnologiesarequitegoodandarereasonableoptionsinsomesituations.Inothersituations,however,JSPisclearlybetter.Hereareafewofthereasons.1.3.1Versus.NETandActiveServerPages(ASP).NETiswell-designedtechnologyfromMicrosoft.isthepartthatdirectlycompeteswithservletsandJSP.TheadvantagesofJSParetwofold. First,JSPisportabletomultipleoperatingsystemsandWebservers;youaren'tlockedintodeployingonWindowsandIIS.Althoughthecore.NETplatformrunsonafewnon-Windowsplatforms,theASPpartdoesnot.Youcannotexpecttodeployseriousapplicationsonmultipleserversandoperatingsystems.Forsomeapplications,thisdifferencedoesnotmatter.Forothers,itmattersgreatly. Second,forsomeapplicationsthechoiceoftheunderlyinglanguagemattersgreatly.Forexample,although.NET'sC#languageisverywelldesignedandissimilartoJava,fewerprogrammersarefamiliarwitheitherthecoreC#syntaxorthemanyauxiliarylibraries.Inaddition,manydevelopersstillusetheoriginalversionofASP.Withthisversion,JSPhasaclearadvantageforthedynamiccode.WithJSP,thedynamicpartiswritteninJava,notVBScriptoranotherASP-specificlanguage,soJSPismorepowerfulandbettersuitedtocomplexapplicationsthatrequirereusablecomponents. YoucouldmakethesameargumentwhencomparingJSPtothepreviousversionofColdFusion;withJSPyoucanuseJavaforthe"realcode"andarenottiedtoaparticularserverproduct.However,thecurrentreleaseofColdFusioniswithinthecontextofaJ2EEserver,allowingdeveloperstoeasilymixColdFusionandservlet/JSPcode.1.3.2VersusPHPPHP(arecursiveacronymfor"PHP:HypertextPreprocessor")isafree,open-source,HTML-embeddedscriptinglanguagethatissomewhatsimilartobothASPandJSP.OneadvantageofJSPisthatthedynamicpartiswritteninJava,whichalreadyhasanextensiveAPIfornetworking,databaseaccess,distributedobjects,andthelike,whereasPHPrequireslearninganentirelynew,lesswidelyusedlanguage.AsecondadvantageisthatJSPismuchmorewidelysupportedbytoolandservervendorsthanisPHP.1.3.3VersusPureServletsJSPdoesn'tprovideanycapabilitiesthatcouldn't,inprinciple,beaccomplishedwithservlets.Infact,JSPdocumentsareautomaticallytranslatedintoservletsbehindthescenes.Butitismoreconvenienttowrite(andtomodify!)regularHTMLthantouseazillionprintlnstatementstogeneratetheHTML.Plus,byseparatingthepresentationfromthecontent,youcanputdifferentpeopleondifferenttasks:yourWebpagedesignexpertscanbuildtheHTMLbyusingfamiliartoolsandeitherleaveplacesforyourservletprogrammerstoinsertthedynamiccontentorinvokethedynamiccontentindirectlybymeansofXMLthismeanthatyoucanjustlearnJSPandforgetaboutservletsAbsolutelynot!JSPdevelopersneedtoknowservletsforfourreasons:(1).JSPpagesgettranslatedintoservlets.Youcan'tunderstandhowJSPworkswithoutunderstandingservlets.(2).JSPconsistsofstaticHTML,special-purposeJSPtags,andJavacode.WhatkindofJavacodeServletcode!Youcan'twritethatcodeifyoudon'tunderstandservletprogramming.(3).SometasksarebetteraccomplishedbyservletsthanbyJSP.JSPisgoodatgeneratingpagesthatconsistoflargesectionsoffairlywellstructuredHTMLorothercharacterdata.Servletsarebetterforgeneratingbinarydata,buildingpageswithhighlyvariablestructure,andperformingtasks(suchasredirection)thatinvolvelittleornooutput.(4).SometasksarebetteraccomplishedbyacombinationofservletsandJSPthanbyeitherservletsorJSPalone.1.3.4VersusJavaScriptJavaScript,whichiscompletelydistinctfromtheJavaprogramminglanguage,isnormallyusedtodynamicallygenerateHTMLontheclient,buildingpartsoftheWebpageasthebrowserloadsthedocument.ThisisausefulcapabilityanddoesnotnormallyoverlapwiththecapabilitiesofJSP(whichrunsonlyontheserver).JSPpagesstillincludeSCRIPTtagsforJavaScript,justasnormalHTMLpagesdo.Infact,JSPcanevenbeusedtodynamicallygeneratetheJavaScriptthatwillbesenttotheclient.So,JavaScriptisnotacompetingtechnology;itisacomplementaryone. ItisalsopossibletouseJavaScriptontheserver,mostnotablyonSunONE(formerlyiPlanet),IIS,andBroadVisionservers.However,Javaismorepowerful,flexible,reliable,andWebMacroorVelocity JSPisbynomeansperfect.Manypeoplehavepointedoutfeaturesthatcouldbeimproved.Thisisagoodthing,andoneoftheadvantagesofJSPisthatthespecificationiscontrolledbyacommunitythatdrawsfrommanydifferentcompanies.So,thetechnologycanincorporateimprovementsinsuccessive,somegroupshavedevelopedalternativeJava-basedtechnologiestotrytoaddressthesedeficiencies.This,inourjudgment,isamistake.Usingathird-partytoollikeApacheStrutsthataugmentsJSPandservlettechnologyisagoodideawhenthattooladdssufficientbenefittocompensatefortheadditionalcomplexity.ButusinganonstandardtoolthattriestoreplaceJSPisabadidea.Whenchoosingatechnology,youneedtoweighmanyfactors:standardization,portability,integration,industrysupport,andtechnicalfeatures.TheargumentsforJSPalternativeshavefocusedalmostexclusivelyonthetechnicalfeaturespart.Butportability,standardization,andintegrationarealsoveryimportant.Forexample,theservletandJSPspecificationsdefineastandarddirectorystructureforWebapplicationsandprovidestandardfiles(.warfiles)fordeployingWebapplications.AllJSP-compatibleserversmustsupportthesestandards.FilterscanbesetuptoapplytoanynumberofservletsorJSPpages,butnottononstandardresources.ThesamegoesforWebapplicationsecurity,thetremendousindustrysupportforJSPandservlettechnologyresultsinimprovementsthatmitigatemanyofthecriticismsofJSP.Forexample,theJSPStandardTagLibraryandtheJSPexpressionlanguageaddresstwoofthemostwell-foundedcriticisms:thelackofgooditerationconstructsandthedifficultyofaccessingdynamicresultswithoutusingeitherexplicitJavacodeorverbosejsp:useBeanelements. MisconceptionsAboutJSPForgettingJSPIsServer-SideTechnologyHerearesometypicalquestionsMartyhasreceived(mostofthemrepeatedly). ?OurserverisrunningJDK.So,howdoIputaSwingcomponentinaJSPpage ?HowdoIputanimageintoaJSPpageIdonotknowtheproperJavaI/Ocommandstoreadimagefiles. ?SinceTomcatdoesnotsupportJavaScript,howdoImakeimagesthatarehighlightedwhentheusermovesthemouseoverthem ?OurclientsuseolderbrowsersthatdonotunderstandJSP.Whatshouldwedo ?Whenourclientsuse"ViewSource"inabrowser,howcanIpreventthemfromseeingtheJSPtagsAllofthesequestionsarebasedupontheassumptionthatbrowsersknowsomethingabouttheserver-sideprocess.Buttheydonot.Thus: ?ForputtingappletswithSwingcomponentsintoWebpages,whatmattersisthebrowser'sJavaversion—theserver'sversionisirrelevant.IfthebrowsersupportstheJava2platform,youusethenormalAPPLET(orJavaplug-in)tagandwoulddosoevenifyouwereusingnon-Javatechnologyontheserver. ?YoudonotneedJavaI/Otoreadimagefiles;youjustputtheimageinthedirectoryforWebresources.,twolevelsupfromWEB-INF/classes)andoutputanormalIMGtag. ?Youcreateimagesthatchangeunderthemousebyusingclient-sideJavaScript,referencedwiththeSCRIPTtag;thisdoesnotchangejustbecausetheserverisusingJSP. ?Browsersdonot"support"JSPatall—theymerelyseetheoutputoftheJSPpage.So,makesureyourJSPoutputsHTMLcompatiblewiththebrowser,justasyouwoulddowithstaticHTMLpages. ?And,ofcourseyouneednotdoanythingtopreventclientsfromseeingJSPtags;thosetagsareprocessedontheserverandarenotpartoftheoutputthatissenttotheTranslationTimewithRequestTimeAJSPpageisconvertedintoaservlet.Theservletiscompiled,loadedintotheserver'smemory,initialized,andexecuted.ButwhichstephappenswhenToanswerthatquestion,remembertwopoints: ?TheJSPpageistranslatedintoaservletandcompiledonlythefirsttimeitisaccessedafterhavingbeenmodified. ?Loadingintomemory,initialization,andexecutionfollowthenormalrulesfor1givessomecommonscenariosandtellswhetherornoteachstepoccursinthatscenario.Themostfrequentlymisunderstoodentriesarehighlighted.Whenreferringtothetable,notethatservletsresultingfromJSPpagesusethe_jspServicemethod(calledforbothGETandPOSTrequests),notdoGetordoPost.Also,forinitialization,theyusethejspInitmethod,nottheinitmethod.

中文翻譯JSP技術(shù)概述 讓我們先對(duì)JSP頁(yè)面的工作方式作一些簡(jiǎn)單的討論。我們將力求簡(jiǎn)單,只將注意力集中于一些基本的方面。有關(guān)詳細(xì)信息,請(qǐng)參閱參考資料中到其他JSP技術(shù)信息的鏈接。從傳統(tǒng)意義上講,JSP頁(yè)面與HTML頁(yè)面很相似,只是多了一些標(biāo)記。這些標(biāo)記使設(shè)計(jì)人員能夠?qū)ava代碼(不是JavaScript)嵌入到頁(yè)面中。Web應(yīng)用程序服務(wù)器(如IBMWebSphereApplicationServer)將截取對(duì)JSP頁(yè)面的請(qǐng)求。頁(yè)面的擴(kuò)展名.jsp(不是.html)向應(yīng)用程序服務(wù)器暗示了這些標(biāo)記的存在。Web應(yīng)用程序服務(wù)器隨后對(duì)JSP頁(yè)面進(jìn)行預(yù)處理,提取其中的JSP標(biāo)記和任何內(nèi)嵌的Java代碼,而只保留HTML。提取出來(lái)的JSP標(biāo)記和內(nèi)嵌Java代碼用來(lái)構(gòu)建Javaservlet(JSP頁(yè)面servlet),Javaservlet運(yùn)行該代碼并將結(jié)果插入到原頁(yè)面中JSP標(biāo)記所在的位置。得到的結(jié)果是純HTML。在請(qǐng)求瀏覽器看到任何結(jié)果之前,Java代碼被剝離并在服務(wù)器上運(yùn)行。 我們可以將同樣的原理應(yīng)用于XML頁(yè)面。在包含XML的JSP頁(yè)面的請(qǐng)求者(可能是一個(gè)瀏覽器,也可能是某個(gè)企業(yè)對(duì)企業(yè)的應(yīng)用程序)看到XML之前,Java代碼被剝離JSP頁(yè)面并用來(lái)生成其他內(nèi)容,生成的內(nèi)容被插入到JSP標(biāo)記原來(lái)所在的頁(yè)面位置。這種特性使您能夠精確地控制將新內(nèi)容插入到什么位置,甚至可以精確到單個(gè)字符。 過(guò)一會(huì)兒我們將考慮如何使用以上的特性。首先,讓我們考慮為什么您可能會(huì)想到用JSP創(chuàng)建動(dòng)態(tài)XML。為什么不只是編寫Java應(yīng)用程序或servlet來(lái)生成整個(gè)文檔為什么要費(fèi)心去使用JSP呢最重要的原因是無(wú)須為每個(gè)請(qǐng)求重新生成靜態(tài)內(nèi)容是有意義的(假定XML文檔只有部分內(nèi)容是動(dòng)態(tài)的)。通過(guò)使用JSP頁(yè)面,頁(yè)面內(nèi)的靜態(tài)XML就可以充當(dāng)一個(gè)模板,該模板是用動(dòng)態(tài)內(nèi)容填充的。Java代碼的任務(wù)僅僅是生成可能隨時(shí)間變化的內(nèi)容--這是一種更有效的方法。 非常現(xiàn)實(shí)的一個(gè)問(wèn)題是,JSP頁(yè)面使您能夠?qū)⒉煌_(kāi)發(fā)人員負(fù)責(zé)的任務(wù)分開(kāi)。特別是,它們?cè)试S您更好地將數(shù)據(jù)與視圖分離開(kāi),從而允許您在不影響邏輯的情況下添加新表示。設(shè)想這樣一個(gè)Javaservlet,它執(zhí)行業(yè)務(wù)邏輯,并根據(jù)請(qǐng)求的性質(zhì)將生成的結(jié)果重定向到適當(dāng)?shù)腏SP頁(yè)面。例如,當(dāng)servlet檢測(cè)到WAP電話瀏覽器發(fā)出請(qǐng)求時(shí),它就可以將數(shù)據(jù)重定向到一個(gè)包含WML的JSP頁(yè)面。對(duì)于標(biāo)準(zhǔn)瀏覽器請(qǐng)求,它可以將數(shù)據(jù)重定向到包括HTML的JSP頁(yè)面。JSP的好處JSP頁(yè)面最終會(huì)轉(zhuǎn)換成servler。因而,從根本上,JSP頁(yè)面能夠執(zhí)行的任何任務(wù)都可以用servler來(lái)完成。然而,這種底層的等同性并不意味著servler和JSP頁(yè)面對(duì)于所有的情況都等同適用。問(wèn)題不在于技術(shù)的能力,而是二者在便利性、生產(chǎn)率和可維護(hù)性上的不同。畢竟,在特定平臺(tái)上能夠用Java編程語(yǔ)言完成的事情,同樣可以用匯編語(yǔ)言來(lái)完成,但是選擇哪種語(yǔ)言依舊十分重要。和單獨(dú)使用servler相比,JSP提供下述好處:中HTML的編寫與維護(hù)更為簡(jiǎn)單。JSP中可以使用常規(guī)的HTML:沒(méi)有額外的反斜杠,沒(méi)有額外的雙引號(hào),也沒(méi)有暗含的Java語(yǔ)法。2.能夠使用標(biāo)準(zhǔn)的網(wǎng)站開(kāi)發(fā)工具。即使對(duì)那些對(duì)JSP一無(wú)所知的HTML工具,我們也可以使用,因?yàn)樗鼈儠?huì)忽略JSP標(biāo)簽(JSPtags)。3.可以對(duì)開(kāi)發(fā)團(tuán)隊(duì)進(jìn)行劃分。Java程序員可以致力于動(dòng)態(tài)代碼。Web開(kāi)發(fā)人員可以將經(jīng)理集中在表示層(presentationlayer)上。對(duì)于大型的項(xiàng)目,這種劃分極為重要。依據(jù)開(kāi)發(fā)團(tuán)隊(duì)的大小,及項(xiàng)目的復(fù)雜程度,可以對(duì)靜態(tài)HTML和動(dòng)態(tài)內(nèi)容進(jìn)行弱分離(weakerseparation)和強(qiáng)分離(strongerseparation)。在此,這個(gè)討論并不是讓您停止使用servlets,只使用JSP。幾乎所有的項(xiàng)目都會(huì)同時(shí)用到這兩種技術(shù)。針對(duì)項(xiàng)目中的某些請(qǐng)求,您可能會(huì)在MVC構(gòu)架下組合使用這兩項(xiàng)技術(shù)。我們總是希望用適當(dāng)?shù)墓ぞ咄瓿上鄬?duì)應(yīng)的工作,僅僅是servlet并不能填滿您的工具箱。JSP相對(duì)于競(jìng)爭(zhēng)技術(shù)的優(yōu)勢(shì)許多年前,Marty受到邀請(qǐng),參加一個(gè)有關(guān)軟件技術(shù)的小型(20個(gè)人)研討會(huì).做在Marty旁邊的人是JamesGoslingJava編程語(yǔ)言的發(fā)明者。隔幾個(gè)位置,是來(lái)自華盛頓一家大型軟件公司的高級(jí)經(jīng)理。在討論過(guò)程中,研討會(huì)的主席提出了Jini的議題,這在當(dāng)時(shí)是一項(xiàng)新的Java技術(shù).主席向該經(jīng)理詢問(wèn)他的想法.他繼續(xù)說(shuō),他們會(huì)持續(xù)關(guān)注這項(xiàng)技術(shù),如果這項(xiàng)技術(shù)變得流行起來(lái),他們會(huì)遵循公司的“接受并擴(kuò)充(embraceandextend)”的策略.此時(shí),Gosling隨意地插話說(shuō)“你的意思其實(shí)就是不接受且不擴(kuò)充(disgraceanddistend)。” 在此,Gosling的抱怨顯示出,他感到這個(gè)公司會(huì)從其他公司那里拿走技術(shù),用于他們自己的目的.但你猜這次怎么樣這次鞋子穿在了另一只腳上。Java社團(tuán)沒(méi)有發(fā)明這一思想將頁(yè)面設(shè)計(jì)成由靜態(tài)HTML和用特殊標(biāo)簽標(biāo)記的動(dòng)態(tài)代碼混合組成.。ColdFusion多年前就已經(jīng)這樣做了。甚至ASP(來(lái)自于前述經(jīng)理所在公司的一項(xiàng)產(chǎn)品)都在JSP出現(xiàn)之前推廣了這種方式。實(shí)際上,JSP不只采用了這種通用概念,它甚至使用許多和ASP相同的特殊標(biāo)簽。因此,問(wèn)題變成:為什么使用JSP,而不使用其他技術(shù)呢我們的第一反應(yīng)是我們不是在爭(zhēng)論所有的人應(yīng)該做什么。其他這些技術(shù)中,有一些也很不錯(cuò),在某些情況下也的確是合情合理的選擇.然而,在其他情形中,JSP明顯要更好一些。下面給出幾個(gè)理由。1.3.1與.NET和ActiveServerPages(ASP)相比.NET是Microsoft精心設(shè)計(jì)的一項(xiàng)技術(shù)。是與servlets和JSP直接競(jìng)爭(zhēng)的技術(shù)。JSP的優(yōu)勢(shì)體現(xiàn)在兩個(gè)方面。 首先,JSP可以移植到多種操作系統(tǒng)和Web服務(wù)器,您不必僅僅局限于部署在Windows和IIS上盡管核心.NET平臺(tái)可以在好幾種非Windows平臺(tái)上運(yùn)行,但ASP這一部分不可以。您不能期望可以將重要的應(yīng)用部署到多種服務(wù)器和操作系統(tǒng)。對(duì)于某些應(yīng)用,這種差異沒(méi)有什么影響。但有些應(yīng)用,這種差異卻非常重要。 其次,對(duì)于某些應(yīng)用,底層語(yǔ)言的選擇至關(guān)重要。例如,盡管.NET的C#語(yǔ)言設(shè)計(jì)優(yōu)良,且和Java類似,但熟悉核心C#語(yǔ)法和眾多工具庫(kù)的程序員很少。此外,許多開(kāi)發(fā)者依舊使用最初版本的ASP。相對(duì)于這個(gè)版本,JSP在動(dòng)態(tài)代碼方面擁有明顯的優(yōu)勢(shì)。使用JSP,動(dòng)態(tài)部分是用Java編寫的,而非VBScript過(guò)其他ASP專有的語(yǔ)言,因此JSP更為強(qiáng)勁,更適合于要求組件重用的復(fù)雜應(yīng)用。 當(dāng)將JSP與之前版本的ColdFusion對(duì)比時(shí),您可能會(huì)得到相同的結(jié)論。應(yīng)用JSP,您可以使用Java編寫“真正的代碼”,不必依賴于特定的服務(wù)器產(chǎn)品。然而,當(dāng)前版本的ColdFusion滿足J2EE服務(wù)器的環(huán)境,允許開(kāi)發(fā)者容易的混合使用ColdFusion和Servlet/JSP代碼。1.3.2與PHP相比PHP(“PHP:HypertextPreprocessor”的遞歸字母縮寫詞)是免費(fèi)的、開(kāi)放源代碼的、HTML嵌入其中的腳本語(yǔ)言,與ASP和JSP都有某種程度的類似。JSP的一項(xiàng)優(yōu)勢(shì)是動(dòng)態(tài)部分用Java編寫,而Java已經(jīng)在聯(lián)網(wǎng)、數(shù)據(jù)庫(kù)訪問(wèn)、分布式對(duì)象等方面擁有廣泛的API,而PHP需要學(xué)習(xí)全新的、應(yīng)用相對(duì)廣泛的語(yǔ)言。JSP的第二項(xiàng)優(yōu)勢(shì)是,和PHP相比,JSP擁有極為廣泛的工具和服務(wù)器提供商的支持。 與純Servlet相比原則上,JSP并沒(méi)有提供Servlet不能完成的功能。實(shí)際上,JSP文檔在后臺(tái)被自動(dòng)轉(zhuǎn)換成Servlet。但是編寫(和修改)常規(guī)的HTML,要比無(wú)數(shù)println語(yǔ)句生成HTML要方便得多。另外,通過(guò)將表示與內(nèi)容分離,可以為不同的人分配不同的任務(wù):網(wǎng)頁(yè)設(shè)計(jì)人員使用熟悉的工具構(gòu)建HTML,要么為Servlet程序員留出空間插入動(dòng)態(tài)內(nèi)容,要么通過(guò)XML標(biāo)簽間接調(diào)用動(dòng)態(tài)內(nèi)容。這是否表示您只可以學(xué)習(xí)JSP,將Servlet丟到一邊呢當(dāng)然不是!由于以下4種原因,JSP開(kāi)發(fā)人員需要了解Servlet:JSP頁(yè)面會(huì)轉(zhuǎn)換成Servlet。不了解Servlet就無(wú)法知道JSP如何工作。JSP由靜態(tài)HTML、專用的JSP標(biāo)簽和Java代碼組成。哪種類型的Java代碼呢當(dāng)然是Servlet代碼!如果不了解Servlet編程,那么就無(wú)法編寫這種代碼。(3)一些任

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論