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

下載本文檔

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

文檔簡介

外文翻譯外文資料和譯文_文檔視界..

XX大學(xué)XXXXXXX

外文資料和譯文

專業(yè):軟件工程

班級:軟件XXXXX

姓名:XXXXX

學(xué)號:XXXXXXXXXXXXXX

指導(dǎo)教師:XXXXXXXX

2009年12月17日

原文

1.1AJSPtechnologyoverview

Let'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.WhynotsimplywriteaJavaapplicationorservlettogeneratetheentiredocument?WhybotherwithJSPatall?Themostimportantreason,providingonlyportionsofanXMLdocumentaredynamic,isthatitmakessensenottoregeneratethat

staticcontentforeveryrequest.UsingaJSPpage,thestaticXMLwithinthepageactsasatemplatethatisfilledoutbythedynamiccontent.YourJavacodeistaskedwithgeneratingonlythecontentthatmightchangeovertime--amoreefficientapproach.

Asapracticalmatter,JSPpagesallowyoutoseparatetasksforwhichdifferentdeveloperswillberesponsible.Inparticular,theyallowyoutobetterseparatethedatafromtheview,allowingyoutoaddnewpresentationswithoutaffectingthelogic.ImaginehavingoneJavaservletthatperformsthebusinesslogicandredirectstheresultingdatatoanappropriateJSPpagebasedonthenatureoftherequest.Forexample,aservletmightredirectdatatoaJSPpagecontainingWMLwhenitdetectsaWAPphonebrowsermakingtherequest.ItcouldalsoredirectthedatatoaJSPpagecontainingHTMLforstandardbrowserrequests.

1.2BenefitsofJSP

JSPpagesaretranslatedintoservlets.So,fundamentally,anytaskJSPpagescanperformcouldalsobeaccomplishedbyservlets.However,thisunderlyingequivalencedoesnotmeanthatservletsandJSPpagesareequallyappropriateinallscenarios.Theissueisnotthepowerofthetechnology,itistheconvenience,productivity,andmaintainabilityofoneortheother.Afterall,anythingyoucandoonaparticularcomputerplatformintheJavaprogramminglanguageyoucouldalsodoinassemblylanguage.Butitstillmatterswhichyouchoose.

JSPprovidesthefollowingbenefitsoverservletsalone:1.ItiseasiertowriteandmaintaintheHTML.YourstaticcodeisordinaryHTML:noextrabackslashes,nodoublequotes,andnolurkingJavasyntax.2.YoucanusestandardWeb-sitedevelopmenttools.EvenHTMLtoolsthatknownothingaboutJSPcanbeusedbecausetheysimplyignoretheJSPtags.3.Youcandivideupyourdevelopmentteam.TheJavaprogrammerscanworkonthedynamiccode.TheWebdeveloperscanconcentrateonthepresentationlayer.

Onlargeprojects,thisdivisionisveryimportant.Dependingonthesizeofyourteamandthecomplexityofyourproject,youcanenforceaweakerorstrongerseparationbetweenthestaticHTMLandthedynamiccontent.Now,thisdiscussionisnottosaythatyoushouldstopusingservletsanduseonlyJSPinstead.Bynomeans.Almostallprojectswilluseboth.Forsomerequestsinyourproject,youwilluseservlets.Forothers,youwilluseJSP.Forstillothers,youwillcombinethemwiththeMVCarchitecture.Youwanttheappropriatetoolforthejob,andservlets,bythemselves,donotcompleteyourtoolkit.

1.3AdvantagesofJSP

OverCompetingTechnologiesAnumberofyearsago,Martywasinvitedtoattendasmall20-personindustryroundtablediscussiononsoftwaretechnology.SittingintheseatnexttoMartywasJamesGosling,inventoroftheJavaprogramminglanguage.Sittingseveralseatsawaywasahigh-levelmanagerfromaverylargesoftwarecompanyinRedmond,Washington.Duringthediscussion,themoderatorbroughtupthesubjectofJini,whichatthattimewasanewJavatechnology.Themoderatoraskedthemanagerwhathethoughtofit,andthemanagerrespondedthatitwastooearlytotell,butthatitseemedtobeanexcellentidea.Hewentontosaythattheywouldkeepaneyeonit,andifitseemedtobecatchingon,theywouldfollowhiscompany'susual"embraceandextend"strategy.Atthispoint,Goslinglightheartedlyinterjected"Youmeandisgraceanddistend."

Now,thegrievancethatGoslingwasairingwasthathefeltthatthiscompanywouldtaketechnologyfromothercompaniesandsubornitfortheirownpurposes.Butguesswhat?Theshoeisontheotherfoothere.TheJavacommunitydidnotinventtheideaofdesigningpagesasamixtureofstaticHTMLanddynamiccodemarkedwithspecialtags.Forexample,ColdFusiondidityearsearlier.EvenASP(aproductfromtheverysoftwarecompany

oftheaforementionedmanager)popularizedthisapproachbeforeJSPcamealonganddecidedtojumponthebandwagon.Infact,JSPnotonlyadoptedthegeneralidea,itevenusedmanyofthesamespecialtagsasASPdid.

So,thequestionbecomes:whyuseJSPinsteadofoneoftheseothertechnologies?Ourfirstresponseisthatwearenotarguingthateveryoneshould.Severalofthoseothertechnologiesarequitegoodandarereasonableoptionsinsomesituations.Inothersituations,however,JSPisclearlybetter.Hereareafewofthereasons.

1.3.1Versus.NETandActiveServerPages(ASP).

NETiswell-designedtechnologyfromMicrosoft.http://./doc/40ef6fe2ab8271fe910ef12d2af90242a995ab21.htmlisthepartthatdirectlycompeteswithservletsandJSP.TheadvantagesofJSParetwofold.

First,JSPisportabletomultipleoperatingsystemsandWebservers;youaren'tlockedintodeployingonWindowsandIIS.Althoughthecore.NETplatformrunsonafewnon-Windowsplatforms,theASPpartdoesnot.Youcannotexpecttodeployserioushttp://./doc/40ef6fe2ab8271fe910ef12d2af90242a995ab21.htmlapplicationsonmultipleserversandoperatingsystems.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"and

arenottiedtoaparticularserverproduct.However,thecurrentreleaseofColdFusioniswithinthecontextofaJ2EEserver,allowingdeveloperstoeasilymixColdFusionandservlet/JSPcode.

1.3.2VersusPHP

PHP(arecursiveacronymfor"PHP:HypertextPreprocessor")isafree,open-source,HTML-embeddedscriptinglanguagethatissomewhatsimilartobothASPandJSP.OneadvantageofJSPisthatthedynamicpartiswritteninJava,whichalreadyhasanextensiveAPIfornetworking,databaseaccess,distributedobjects,andthelike,whereasPHPrequireslearninganentirelynew,lesswidelyusedlanguage.AsecondadvantageisthatJSPismuchmorewidelysupportedbytoolandservervendorsthanisPHP.

1.3.3VersusPureServlets

JSPdoesn'tprovideanycapabilitiesthatcouldn't,inprinciple,beaccomplishedwithservlets.Infact,JSPdocumentsareautomaticallytranslatedintoservletsbehindthescenes.Butitismoreconvenienttowrite(andtomodify!)regularHTMLthantouseazillionprintlnstatementstogeneratetheHTML.Plus,byseparatingthepresentationfromthecontent,youcanputdifferentpeopleondifferenttasks:yourWebpagedesignexpertscanbuildtheHTMLbyusingfamiliartoolsandeitherleaveplacesforyourservletprogrammerstoinsertthedynamiccontentorinvokethedynamiccontentindirectlybymeansofXMLtags.DoesthismeanthatyoucanjustlearnJSPandforgetaboutservlets?Absolutelynot!JSPdevelopersneedtoknowservletsforfourreasons:

(1).JSPpagesgettranslatedintoservlets.Youcan'tunderstandhowJSPworkswithoutunderstandingservlets.

(2).JSPconsistsofstaticHTML,special-purposeJSPtags,andJavacode.WhatkindofJavacode?Servletcode!Youcan'twritethatcodeifyoudon'tunderstandservletprogramming.

(3).SometasksarebetteraccomplishedbyservletsthanbyJSP.JSPisgoodatgeneratingpagesthatconsistoflargesectionsoffairlywellstructuredHTMLorothercharacterdata.Servletsarebetterforgeneratingbinarydata,buildingpageswithhighlyvariablestructure,andperformingtasks(suchasredirection)thatinvolvelittleornooutput.

(4).SometasksarebetteraccomplishedbyacombinationofservletsandJSPthanbyeitherservletsorJSPalone.

1.3.4VersusJavaScript

JavaScript,whichiscompletelydistinctfromtheJavaprogramminglanguage,isnormallyusedtodynamicallygenerateHTMLontheclient,buildingpartsoftheWebpageasthebrowserloadsthedocument.ThisisausefulcapabilityanddoesnotnormallyoverlapwiththecapabilitiesofJSP(whichrunsonlyontheserver).JSPpagesstillincludeSCRIPTtagsforJavaScript,justasnormalHTMLpagesdo.Infact,JSPcanevenbeusedtodynamicallygeneratetheJavaScriptthatwillbesenttotheclient.So,JavaScriptisnotacompetingtechnology;itisacomplementaryone.

ItisalsopossibletouseJavaScriptontheserver,mostnotablyonSunONE(formerlyiPlanet),IIS,andBroadVisionservers.However,Javaismorepowerful,flexible,reliable,andportable.VersusWebMacroorVelocity

JSPisbynomeansperfect.Manypeoplehavepointedoutfeaturesthatcouldbeimproved.Thisisagoodthing,andoneoftheadvantagesofJSPisthatthespecificationiscontrolledbyacommunitythatdrawsfrommanydifferentcompanies.So,thetechnologycanincorporateimprovementsinsuccessivereleases.However,somegroupshavedevelopedalternativeJava-basedtechnologiestotrytoaddressthesedeficiencies.This,inourjudgment,isamistake.Usingathird-partytoollikeApacheStruts

thataugmentsJSPandservlettechnologyisagoodideawhenthattooladdssufficientbenefittocompensatefortheadditionalcomplexity.ButusinganonstandardtoolthattriestoreplaceJSPisabadidea.Whenchoosingatechnology,youneedtoweighmanyfactors:standardization,portability,integration,industrysupport,andtechnicalfeatures.TheargumentsforJSPalternativeshavefocusedalmostexclusivelyonthetechnicalfeaturespart.Butportability,standardization,andintegrationarealsoveryimportant.Forexample,theservletandJSPspecificationsdefineastandarddirectorystructureforWebapplicationsandprovidestandardfiles(.warfiles)fordeployingWebapplications.AllJSP-compatibleserversmustsupportthesestandards.FilterscanbesetuptoapplytoanynumberofservletsorJSPpages,butnottononstandardresources.ThesamegoesforWebapplicationsecuritysettings.Besides,thetremendousindustrysupportforJSPandservlettechnologyresultsinimprovementsthatmitigatemanyofthecriticismsofJSP.Forexample,theJSPStandardTagLibraryandtheJSP2.0expressionlanguageaddresstwoofthemostwell-foundedcriticisms:thelackofgooditerationconstructsandthedifficultyofaccessingdynamicresultswithoutusingeitherexplicitJavacodeorverbosejsp:useBeanelements.

1.4MisconceptionsAboutJSP

ForgettingJSPIsServer-SideTechnologyHerearesometypicalquestionsMartyhasreceived(mostofthemrepeatedly).

?OurserverisrunningJDK1.4.So,howdoIputaSwingcomponentinaJSPpage?

?HowdoIputanimageintoaJSPpage?IdonotknowtheproperJavaI/Ocommandstoreadimagefiles.

?SinceTomcatdoesnotsupportJavaScript,howdoImakeimagesthatarehighlightedwhentheusermovesthemouseoverthem?

?OurclientsuseolderbrowsersthatdonotunderstandJSP.Whatshouldwedo?

?Whenourclientsuse"ViewSource"inabrowser,howcanIpreventthemfromseeingtheJSPtags?Allofthesequestionsarebasedupontheassumptionthatbrowsersknowsomethingabouttheserver-sideprocess.Buttheydonot.Thus:

?ForputtingappletswithSwingcomponentsintoWebpages,whatmattersisthebrowser'sJavaversion—theserver'sversionisirrelevant.IfthebrowsersupportstheJava2platform,youusethenormalAPPLET(orJavaplug-in)tagandwoulddosoevenifyouwereusingnon-Javatechnologyontheserver.

?YoudonotneedJavaI/Otoreadimagefiles;youjustputtheimageinthedirectoryforWebresources(i.e.,twolevelsupfromWEB-INF/classes)andoutputanormalIMGtag.

?Youcreateimagesthatchangeunderthemousebyusingclient-sideJavaScript,referencedwiththeSCRIPTtag;thisdoesnotchangejustbecausetheserverisusingJSP.

?Browsersdonot"support"JSPatall—theymerelyseetheoutputoftheJSPpage.So,makesureyourJSPoutputsHTMLcompatiblewiththebrowser,justasyouwoulddowithstaticHTMLpages.

?And,ofcourseyouneednotdoanythingtopreventclientsfromseeingJSPtags;thosetagsareprocessedontheserverandarenotpartoftheoutputthatissenttotheclient.ConfusingTranslationTimewithRequestTimeAJSPpageisconvertedintoaservlet.Theservletiscompiled,loadedintotheserver'smemory,initialized,andexecuted.Butwhichstephappenswhen?Toanswerthatquestion,remembertwopoints:?TheJSPpageistranslatedintoaservletandcompiledonlythefirsttimeitisaccessedafterhavingbeenmodified.

?Loadingintomemory,initialization,andexecutionfollowthe

normalrulesforservlets.Table1givessomecommonscenariosandtellswhetherornoteachstepoccursinthatscenario.Themostfrequentlymisunderstoodentriesarehighlighted.Whenreferringtothetable,notethatservletsresultingfromJSPpagesusethe_jspServicemethod(calledforbothGETandPOSTrequests),notdoGetordoPost.Also,forinitialization,theyusethejspInitmethod,nottheinitmethod.

中文翻譯

1.1JSP技術(shù)概述

讓我們先對JSP頁面的工作方式作一些簡單的討論。我們將力求簡單,只將注意力集中于一些基本的方面。有關(guān)詳細(xì)信息,請參閱參考資料中到其他JSP技術(shù)信息的。

從傳統(tǒng)意義上講,JSP頁面與HTML頁面很相似,只是多了一些標(biāo)記。這些標(biāo)記使設(shè)計(jì)人員能夠?qū)ava代碼(不是JavaScript)嵌入到頁面中。Web應(yīng)用程序服務(wù)器(如IBMWebSphereApplicationServer)將截取對JSP頁面的請求。頁面的擴(kuò)展名.jsp(不是.html)向應(yīng)用程序服務(wù)器暗示了這些標(biāo)記的存在。Web應(yīng)用程序服務(wù)器隨后對JSP頁面進(jìn)行預(yù)處理,提取其中的JSP標(biāo)記和任何嵌的Java代碼,而只保留HTML。提取出來的JSP標(biāo)記和嵌Java代碼用來構(gòu)建Javaservlet(JSP頁面servlet),Javaservlet運(yùn)行該代碼并將結(jié)果插入到原頁面中JSP標(biāo)記所在的位置。得到的結(jié)果是純HTML。在請求瀏覽器看到任何結(jié)果之前,Java代碼被剝離并在服務(wù)器上運(yùn)行。

我們可以將同樣的原理應(yīng)用于XML頁面。在包含XML的JSP頁面的請求者(可能是一個(gè)瀏覽器,也可能是某個(gè)企業(yè)對企業(yè)的應(yīng)用程序)看到XML之前,Java代碼被剝離JSP頁面并用來生成其他容,生成的容被插入到JSP標(biāo)記原來所在的頁面位置。這種特性使您能夠精確地控制將新容插入到什么位置,甚至可以精確到單個(gè)字符。

過一會兒我們將考慮如何使用以上的特性。首先,讓我們考慮為什么您可能會想到用JSP創(chuàng)建動(dòng)態(tài)XML。為什么不只是編寫Java應(yīng)用程序或servlet來生成整個(gè)文檔?為什么要費(fèi)心去使用JSP呢?最重要的原因是無須為每個(gè)請求重新生成靜態(tài)容是有意義的(假定XML文檔只有部分容是動(dòng)態(tài)的)。通過使用JSP頁面,頁面的靜態(tài)XML就可以充當(dāng)一個(gè)模板,該模板是用動(dòng)態(tài)容填充的。Java代碼的任務(wù)僅僅是生成可能隨時(shí)間變化的容--這是一種更有效的方法。

非?,F(xiàn)實(shí)的一個(gè)問題是,JSP頁面使您能夠?qū)⒉煌_發(fā)人員負(fù)責(zé)的任務(wù)分開。特別是,它們允許您更好地將數(shù)據(jù)與視圖分離開,從而允許您在不影響邏輯的情況下添加新表示。設(shè)想這樣一個(gè)Javaservlet,它執(zhí)行業(yè)務(wù)邏輯,并根據(jù)請求

的性質(zhì)將生成的結(jié)果重定向到適當(dāng)?shù)腏SP頁面。例如,當(dāng)servlet檢測到WAP瀏覽器發(fā)出請求時(shí),它就可以將數(shù)據(jù)重定向到一個(gè)包含WML的JSP頁面。對于標(biāo)準(zhǔn)瀏覽器請求,它可以將數(shù)據(jù)重定向到包括HTML的JSP頁面。

1.2JSP的好處

JSP頁面最終會轉(zhuǎn)換成servler。因而,從根本上,JSP頁面能夠執(zhí)行的任何任務(wù)都可以用servler來完成。然而,這種底層的等同性并不意味著servler和JSP頁面對于所有的情況都等同適用。問題不在于技術(shù)的能力,而是二者在便利性、生產(chǎn)率和可維護(hù)性上的不同。畢竟,在特定平臺上能夠用Java編程語言完成的事情,同樣可以用匯編語言來完成,但是選擇哪種語言依舊十分重要。和單獨(dú)使用servler相比,JSP提供下述好處:1.JSP中HTML的編寫與維護(hù)更為簡單。JSP中可以使用常規(guī)的HTML:沒有額外的反斜杠,沒有額外的雙引號,也沒有暗含的Java語法。2.能夠使用標(biāo)準(zhǔn)的開發(fā)工具。即使對那些對JSP一無所知的HTML工具,我們也可以使用,因?yàn)樗鼈儠雎訨SP標(biāo)簽(JSPtags)。3.可以對開發(fā)團(tuán)隊(duì)進(jìn)行劃分。Java程序員可以致力于動(dòng)態(tài)代碼。Web開發(fā)人員可以將經(jīng)理集中在表示層(presentationlayer)上。對于大型的項(xiàng)目,這種劃分極為重要。依據(jù)開發(fā)團(tuán)隊(duì)的大小,及項(xiàng)目的復(fù)雜程度,可以對靜態(tài)HTML和動(dòng)態(tài)容進(jìn)行弱分離(weakerseparation)和強(qiáng)分離(strongerseparation)。在此,這個(gè)討論并不是讓您停止使用servlets,只使用JSP。幾乎所有的項(xiàng)目都會同時(shí)用到這兩種技術(shù)。針對項(xiàng)目中的某些請求,您可能會在MVC構(gòu)架下組合使用這兩項(xiàng)技術(shù)。我們總是希望用適當(dāng)?shù)墓ぞ咄瓿上鄬?yīng)的工作,僅僅是servlet并不能填滿您的工具箱。

1.3JSP相對于競爭技術(shù)的優(yōu)勢

許多年前,Marty受到邀請,參加一個(gè)有關(guān)軟件技術(shù)的小型(20個(gè)人)研討會.做在Marty旁邊的人是JamesGoslingJava編程語言的發(fā)明者。隔幾個(gè)位置,是來自華盛頓一家大型軟件公司的高級經(jīng)理。在討論過程中,研討會的主席提出了Jini的議題,這在當(dāng)時(shí)是一項(xiàng)新的Java技術(shù).主席向該經(jīng)理詢問他的想法.他繼續(xù)說,他們會持續(xù)關(guān)注這項(xiàng)技術(shù),如果這項(xiàng)技術(shù)變得流行起來,他們會遵循公司的“接受并擴(kuò)充(embraceandextend)”的策略.此時(shí),Gosling隨意地插話說“你的意思其實(shí)就是不接受且不擴(kuò)充(disgraceanddistend)?!?/p>

在此,Gosling的抱怨顯示出,他感到這個(gè)公司會從其他公司那里拿走技術(shù),用于他們自己的目的.但你猜這次怎么樣?這次鞋子穿在了另一只腳上。Java社團(tuán)沒有發(fā)明這一思想將頁面設(shè)計(jì)成由靜態(tài)HTML和用特殊標(biāo)簽標(biāo)記的動(dòng)態(tài)代碼混合組成.。ColdFusion多年前就已經(jīng)這樣做了。甚至ASP(來自于前述經(jīng)理所在公司的一項(xiàng)產(chǎn)品)都在JSP出現(xiàn)之前推廣了這種方式。實(shí)際上,JSP不只采用了這種通用概念,它甚至使用許多和ASP相同的特殊標(biāo)簽。因此,問題變成:為什么使用JSP,而不使用其他技術(shù)呢?我們的第一反應(yīng)是我們不是在爭論所有的人應(yīng)該做什么。其他這些技術(shù)中,有一些也很不錯(cuò),在某些情況下也的確是合情合理的選擇.然而,在其他情形中,JSP明顯要更好一些。下面給出幾個(gè)理由。

1.3.1與.NET和ActiveServerPages(ASP)相比.

NET是Microsoft精心設(shè)計(jì)的一項(xiàng)技術(shù)。http://./doc/40ef6fe2ab8271fe910ef12d2af90242a995ab21.html是與servlets和JSP直接競爭的技術(shù)。JSP的優(yōu)勢體現(xiàn)在兩個(gè)方面。

首先,JSP可以移植到多種操作系統(tǒng)和Web服務(wù)器,您不必僅僅局限于部署在Windows和IIS上盡管核心.NET平臺可以在好幾種非Windows平臺上運(yùn)行,但ASP這一部分不可以。您不能期望可以將重要的http://./doc/40ef6fe2ab8271fe910ef12d2af90242a995ab21.html應(yīng)用部署到多種服務(wù)器和操作系統(tǒng)。對于某些應(yīng)用,這種差異沒有什么影響。但有些應(yīng)用,這種差異卻非常重要。

其次,對于某些應(yīng)用,底層語言的選擇至關(guān)重要。例如,盡管.NET的C#語言設(shè)計(jì)優(yōu)良,且和Java類似,但熟悉核心C#語法和眾多工具庫的程序員很少。此外,許多開發(fā)者依舊使用最初版本的ASP。相對于這個(gè)版本,JSP在動(dòng)態(tài)代碼方面擁有明顯的優(yōu)勢。使用JSP,動(dòng)態(tài)部分是用Java編寫的,而非VBScript過其他ASP專有的語言,因此JSP更為強(qiáng)勁,更適合于要求組件重用的復(fù)雜應(yīng)用。

當(dāng)將JSP與之前版本的ColdFusion對比時(shí),您可能會得到相同的結(jié)論。應(yīng)用JSP,您可以使用Java編寫“真正的代碼”,不必依賴于特定的服務(wù)器產(chǎn)品。然而,當(dāng)前版本的ColdFusion滿足J2EE服務(wù)器的環(huán)境,允許開發(fā)者容易的混合使用ColdFusion和Servlet/JSP代碼。

1.3.2與PHP相比

PHP(“PHP:HypertextPreprocessor”的遞歸字母縮寫詞)是免費(fèi)的、開放源代碼的、HTML嵌入其中的腳本語言,與ASP和JSP都有某種程度的類似。JSP

的一項(xiàng)優(yōu)勢是動(dòng)態(tài)部分用Java編寫,而Java已經(jīng)在聯(lián)網(wǎng)、數(shù)據(jù)庫訪問、分布式對象等方面擁有廣泛的API,而PHP需要學(xué)習(xí)全新的、應(yīng)用相對廣泛的語言。JSP的第二項(xiàng)優(yōu)勢是,和PHP相比,JSP擁有極為廣泛的工具和服務(wù)器提供商的支持。

與純Servlet相比原則上,JSP并沒有提供Servlet不能完成的功能。實(shí)際上,JSP文檔在后臺被自動(dòng)轉(zhuǎn)換成Servlet。但是編寫(和修改)常規(guī)的HTML,要比無數(shù)println語句生成HTML要方便得多。另外,通過將表示與容分離,可以為不同的人分配不同的任務(wù):網(wǎng)頁設(shè)計(jì)人員使用熟悉的工具構(gòu)建HTML,要么為Servlet程序員留出空間插入動(dòng)態(tài)容,要么通過XML標(biāo)簽間接調(diào)用動(dòng)態(tài)容。這是否表示您只可以學(xué)習(xí)JSP,將Servlet丟到一邊呢?當(dāng)然不是!由于以下4種原因,JSP開發(fā)人員需要了解Servlet:

(1)JSP頁面會轉(zhuǎn)換成Servlet。不了解Servlet就無法知道JSP如何工作。(2)JSP由靜態(tài)HTML、專用的JSP標(biāo)簽和Java代碼組成。哪種類型的Java代碼呢?當(dāng)然是Servlet代碼!如果不了解Servlet編程,那么就無法編寫這種代碼。

溫馨提示

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

最新文檔

評論

0/150

提交評論