JSP應(yīng)用框架中英文對照外文翻譯文獻_第1頁
JSP應(yīng)用框架中英文對照外文翻譯文獻_第2頁
JSP應(yīng)用框架中英文對照外文翻譯文獻_第3頁
JSP應(yīng)用框架中英文對照外文翻譯文獻_第4頁
JSP應(yīng)用框架中英文對照外文翻譯文獻_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

外文翻譯PAGEPAGE11中英文對照外文翻譯文JSPAPPLICATIONFRAMEWORKS1.1WHATAREAPPLICATIONFRAMEWORKS:Aframeworkisareusable,semi-completeapplicationthatcanbespecializedtoproducecustomapplications[Johnson].Likepeople,softwareapplicationsaremorealikethantheyaredifferent.Theyrunonthesamecomputers,expectinputfromthesamedevices,outputtothesamedisplays,andsavedatatothesameharddisks.Developersworkingonconventionaldesktopapplicationsareaccustomedtotoolkitsanddevelopmentenvironmentsthatleveragethesamenessbetweenapplications.Applicationframeworksbuildonthiscommongroundtoprovidedeveloperswithareusablestructurethatcanserveasthefoundationfortheirownproducts.Aframeworkprovidesdeveloperswithasetofbackbonecomponentsthathavethefollowingcharacteristics:Frameworksaretheclassicbuild-versus-buyproposition.Ifyoubuildit,youwillunderstanditwhenyouaredone—buthowlongwillitbebeforeyoucanrollyourown?Ifyoubuyit,youwillhavetoclimbthelearningcurve—andhowlongisthatgoingtotake?Thereisnorightanswerhere,butmostobserverswouldagreethatframeworkssuchasStrutsprovideasignificantreturnoninvestmentcomparedtostartingfromscratch,especiallyforlargerprojects.1.2OTHERTYPESOFFRAMEWORKS:Theideaofaframeworkappliesnotonlytoapplicationsbuttoapplicationcomponentsaswell.Throughoutthisarticle,weintroduceothertypesofframeworksthatyoucanusewithStruts.TheseincludetheLucenesearchengine,theScaffoldtoolkit,theStrutsvalidator,andtheTilestaglibrary.Likeapplicationframeworks,thesetoolsprovidesemi-completeversionsofasubsystemthatcanbespecializedtoprovideacustomcomponent.Someframeworkshavebeenlinkedtoaproprietarydevelopmentenvironment.ThisisnotthecasewithStrutsoranyoftheotherframeworksshowninthisbook.YoucanuseanydevelopmentenvironmentwithStruts:VisualAgeforJava,JBuilder,Eclipse,Emacs,andTextpadareallpopularchoicesamongStrutsdevelopers.IfyoucanuseitwithJava,youcanuseitwithStruts.1.3ENABLINGTECHNOLPGIES:ApplicationsdevelopedwithStrutsarebasedonanumberofenablingtechnologies.ThesecomponentsarenotspecifictoStrutsandunderlieeveryJavawebapplication.AreasonthatdevelopersuseframeworkslikeStrutsistohidethenastydetailsbehindacronymslikeHTTP,CGI,andJSP.AsaStrutsdeveloper,youdon’tneedtobeanalphabetsoupguru,butaworkingknowledgeofthesebasetechnologiescanhelpyoudevisecreativesolutionstotrickyproblems.1.4HYPERTEXTTRANSFERPROTOCOL(HTTP):Whenmediatingtalksbetweennations,diplomatsoftenfollowaformalprotocol.Diplomaticprotocolsaredesignedtoavoidmisunderstandingsandtokeepnegotiationsfrombreakingdown.Inasimilarvein,whencomputersneedtotalk,theyalsofollowaformalprotocol.Theprotocoldefineshowdataistransmittedandhowtodecodeitonceitarrives.WebapplicationsusetheHypertextTransferProtocol(HTTP)tomovedatabetweenthebrowserrunningonyourcomputerandtheapplicationrunningontheserver.ManyserverapplicationscommunicateusingprotocolsotherthanHTTP.Someofthesemaintainanongoingconnectionbetweenthecomputers.Theapplicationserverknowsexactlywhoisconnectedatalltimesandcantellwhenaconnectionisdropped.Becausetheyknowthestateofeachconnectionandtheidentityofeachpersonusingit,theseareknownasstatefulprotocols.Bycontrast,HTTPisknownasastatelessprotocol.AnHTTPserverwillacceptanyrequestfromanyclientandwillalwaysprovidesometypeofresponse,eveniftheresponseisjusttosayno.Withouttheoverheadofnegotiatingandretainingaconnection,statelessprotocolscanhandlealargevolumeofrequests.ThisisonereasonwhytheInternethasbeenabletoscaletomillionsofcomputers.AnotherreasonHTTPhasbecometheuniversalstandardisitssimplicity.AnHTTPrequestlookslikeanordinarytextdocument.ThishasmadeiteasyforapplicationstomakeHTTPrequests.YoucanevensendanHTTPrequestbyhandusingastandardutilitysuchasTelnet.WhentheHTTPresponsecomesback,itisalsoinplaintextthatdeveloperscanread.ThefirstlineintheHTTPrequestcontainsthemethod,followedbythelocationoftherequestedresourceandtheversionofHTTP.ZeroormoreHTTPrequestheadersfollowtheinitialline.TheHTTPheadersprovideadditionalinformationtotheserver.Thiscanincludethebrowsertypeandversion,acceptabledocumenttypes,andthebrowser’scookies,justtonameafew.Ofthesevenrequestmethods,GETandPOSTarebyfarthemostpopular.Oncetheserverhasreceivedandservicedtherequest,itwillissueanHTTPresponse.ThefirstlineintheresponseiscalledthestatuslineandcarriestheHTTPprotocolversion,anumericstatus,andabriefdescriptionofthestatus.Followingthestatusline,theserverwillreturnasetofHTTPresponseheadersthatworkinawaysimilartotherequestheaders.Aswementioned,HTTPdoesnotpreservestateinformationbetweenrequests.Theserverlogstherequest,sendstheresponse,andgoesblissfullyontothenextrequest.Whilesimpleandefficient,astatelessprotocolisproblematicfordynamicapplicationsthatneedtokeeptrackoftheirusers.CookiesandURLrewritingaretwocommonwaystokeeptrackofusersbetweenrequests.Acookieisaspecialpacketofinformationontheuser’scomputer.URLrewritingstoresaspecialreferenceinthepageaddressthataJavaservercanusetotrackusers.Bothapproachesareseamless,andusingeithermeansextraworkwhendevelopingawebapplication.Onitsown,astandardHTTPwebserverdoesnottrafficindynamiccontent.Itmainlyusestherequesttolocateafileandthenreturnsthatfileintheresponse.ThefileistypicallyformattedusingHypertextMarkupLanguage(HTML)[W3C,HTML]thatthewebbrowsercanformatanddisplay.TheHTMLpageoftenincludeshypertextlinkstootherwebpagesandmaydisplayanynumberofothergoodies,suchasimagesandvideos.Theuserclicksalinktomakeanotherrequest,andtheprocessbeginsanew.Standardwebservershandlestaticcontentandimagesquitewellbutneedahelpinghandtoprovideuserswithacustomized,dynamicresponse.DEFINITION:StaticcontentontheWebcomesdirectlyfromtextordatafiles,likeHTMLorJPEGfiles.Thesefilesmightbechangedfromtimetotime,buttheyarenotalteredautomaticallywhenrequestedbyawebbrowser.Dynamiccontent,ontheotherhand,isgeneratedonthefly,typicallyinresponsetoanindividualizedrequestfromabrowser.1.5COMMONGATEWAYINTERFACE(CGI):ThefirstwidelyusedstandardforproducingdynamiccontentwastheCommonGatewayInterface(CGI).CGIusesstandardoperatingsystemfeatures,suchasenvironmentvariablesandstandardinputandoutput,tocreateabridge,orgateway,betweenthewebserverandotherapplicationsonthehostmachine.Theotherapplicationscanlookattherequestsenttothembythewebserverandcreateacustomizedresponse.Whenawebserverreceivesarequestthat’sintendedforaCGIprogram,itrunsthatprogramandprovidestheprogramwithinformationfromtheincomingrequest.TheCGIprogramrunsandsendsitsoutputbacktotheserver.Thewebserverthenrelaystheresponsetothebrowser.CGIdefinesasetofconventionsregardingwhatinformationitwillpassasenvironmentvariablesandhowitexpectsstandardinputandoutputtobeused.LikeHTTP,CGIisflexibleandeasytoimplement,andagreatnumberofCGI-awareprogramshavebeenwritten.ThemaindrawbacktoCGIisthatitmustrunanewcopyoftheCGI-awareprogramforeachrequest.Thisisarelativelyexpensiveprocessthatcanbogdownhigh-volumesiteswherethousandsofrequestsareservicedperminute.AnotherdrawbackisthatCGIprogramstendtobeplatformdependent.ACGIprogramwrittenforoneoperatingsystemmaynotrunonanother.1.6JAVASERVLETS:Sun’sJavaServletplatformdirectlyaddressesthetwomaindrawbacksofCGIprograms.First,servletsofferbetterperformanceandutilizationofresourcesthanconventionalCGIprograms.Second,thewrite-once,run-anywherenatureofJavameansthatservletsareportablebetweenoperatingsystemsthathaveaJavaVirtualMachine(JVM).AServletlooksandfeelslikeaminiaturewebserver.Itreceivesarequestandrendersaresponse.But,unlikeconventionalwebservers,theServletapplicationprogramminginterface(API)isspecificallydesignedtohelpJavadeveloperscreatedynamicapplications.TheServletitselfissimplyaJavaclassthathasbeencompiledintobytecode,likeanyotherJavaobject.TheServlethasaccesstoarichAPIofHTTP-specificservices,butitisstilljustanotherJavaobjectrunninginanapplicationandcanleverageallyourotherJavaassets.Togiveconventionalwebserversaccesstoservlets,theservletsarepluggedintocontainers.TheServletcontainerisattachedtothewebserver.EachServletcandeclarewhatURLpatternsitwouldliketohandle.Whenarequestmatchingaregisteredpatternarrives,thewebserverpassestherequesttothecontainer,andthecontainerinvokestheServlet.ButunlikeCGIprograms,anewServletisnotcreatedforeachrequest.OncethecontainerinstantiatestheServlet,itwilljustcreateanewthreadforeachrequest.JavathreadsaremuchlessexpensivethantheserverprocessesusedbyCGIprograms.OncetheServlethasbeencreated,usingitforadditionalrequestsincursverylittleoverhead.Servletdeveloperscanusetheinit()methodtoholdreferencestoexpensiveresources,suchasdatabaseconnectionsorEJBHomeInterfaces,sothattheycanbesharedbetweenrequests.Acquiringresourceslikethesecantakeseveralseconds—whichislongerthanmanysurfersarewillingtowait.Theotheredgeoftheswordisthat,sinceservletsaremultithreaded,Servletdevelopersmusttakespecialcaretobesuretheirservletsarethread-safe.1.7JAVASERVERPAGES:WhileJavaservletsareabigstepupfromCGIprograms,theyarenotapanacea.Togeneratetheresponse,developersarestillstuckwithusingprintlnstatementstorendertheHTML.Codethatlookslike:out.println("<P>OnelineofHTML.</P>");out.println("<P>AnotherlineofHTML.</P>");ItisalltoocommoninservletsthatgeneratetheHTTPresponse.TherearelibrariesthatcanhelpyougenerateHTML,butasapplicationsgrowmorecomplex,JavadevelopersendupbeingcastintotheroleofHTMLpagedesigners.Meanwhile,giventhechoice,mostprojectmanagersprefertodividedevelopmentteamsintospecializedgroups.TheylikeHTMLdesignerstobeworkingonthepresentationwhileJavaengineerssweatthebusinesslogic.Usingservletsaloneencouragesmixingmarkupwithbusinesslogic,makingitdifficultforteammemberstospecialize.Tosolvethisproblem,Sunturnedtotheideaofusingserverpagestocombinescriptingandtemplatingtechnologiesintoasinglecomponent.TobuildJavaServerPages,developersstartbycreatingHTMLpagesinthesameoldway,usingthesameoldHTMLsyntax.Tobringdynamiccontentintothepage,thedevelopercanalsoplaceJSPscriptingelementsonthepage.ScriptingelementsaretagsthatencapsulatelogicthatisrecognizedbytheJSP.YoucaneasilypickoutscriptingelementsonJSPpagesbylookingforcodethatbeginswith<%andendswith%>.TobeseenasaJSPpage,thefilejustneedstobesavedwithanextensionofjsp.WhenaclientrequeststheJSPpage,thecontainertranslatesthepageintoasourcecodefileforaJavaServletandcompilesthesourceintoaJavaclassfile—justasyouwoulddoifyouwerewritingaServletfromscratch.Atruntime,thecontainercanalsocheckthelastmodifieddateoftheJSPfileagainsttheclassfile.IftheJSPfilehaschangedsinceitwaslastcompiled,thecontainerwillretranslateandrebuildthepagealloveragain.ProjectmanagerscannowassignthepresentationlayertoHTMLdevelopers,whothenpassontheirworktoJavadeveloperstocompletethebusiness-logicportion.TheimportantthingtorememberisthataJSPpageisreallyjustaServlet.AnythingyoucandowithaServlet,youcandowithaJSP.1.8JAVABEANS:JavaBeansareJavaclasseswhichconformtoasetofdesignpatternsthatmakethemeasiertousewithdevelopmenttoolsandothercomponents.DEFINITION:AJavaBeanisareusablesoftwarecomponentwritteninJava.ToqualifyasaJavaBean,theclassmustbeconcreteandpublic,andhaveanon-argumentconstructor.JavaBeansexposeinternalfieldsaspropertiesbyprovidingpublicmethodsthatfollowaconsistentdesignpattern.Knowingthatthepropertynamesfollowthispattern,otherJavaclassesareabletouseintrospectiontodiscoverandmanipulateJavaBeanproperties.TheJavaBeandesignpatternsprovideaccesstothebean’sinternalstatethroughtwoflavorsofmethods:accessorsareusedtoreadaJavaBean’sstate;mutatorsareusedtochangeaJavaBean’sstate.Mutatorsarealwaysprefixedwithlowercasetokensetfollowedbythepropertyname.Thefirstcharacterinthepropertynamemustbeuppercase.Thereturnvalueisalwaysvoid—mutatorsonlychangepropertyvalues,theydonotretrievethem.Themutatorforasimplepropertytakesonlyoneparameterinitssignature,whichcanbeofanytype.Mutatorsareoftennicknamedsettersaftertheirprefix.ThemutatormethodsignatureforaweightpropertyofthetypeDoublewouldbe:publicvoidsetWeight(Doubleweight);Asimilardesignpatternisusedtocreatetheaccessormethodsignature.Accessormethodsarealwaysprefixedwiththelowercasetokenget,followedbythepropertyname.Thefirstcharacterinthepropertynamemustbeuppercase.Thereturnvaluewillmatchthemethodparameterinthecorrespondingmutator.Accessorsforsimplepropertiescannotacceptparametersintheirmethodsignature.Notsurprisingly,accessorsareoftencalledgetters.Theaccessormethodsignatureforourweightpropertyis:publicDoublegetWeight();Iftheaccessorreturnsalogicalvalue,thereisavariantpattern.Insteadofusingthelowercasetokenget,alogicalpropertycanusetheprefixis,followedbythepropertyname.Thefirstcharacterinthepropertynamemustbeuppercase.Thereturnvaluewillalwaysbealogicalvalue—eitherbooleanorBoolean.Logicalaccessorscannotacceptparametersintheirmethodsignature.Thebooleanaccessormethodsignatureforanonpropertywouldbe:publicbooleanisOn();ThecanonicalmethodsignaturesplayanimportantrolewhenworkingwithJava-Beans.OthercomponentsareabletousetheJavaReflectionAPItodiscoveraJavaBean’spropertiesbylookingformethodsprefixedbyset,is,orget.IfacomponentfindssuchasignatureonaJavaBean,itknowsthatthemethodcanbeusedtoaccessorchangethebean’sproperties.SunintroducedJavaBeanstoworkwithGUIcomponents,buttheyarenowusedwitheveryaspectofJavadevelopment,includingwebapplications.WhenSunengineersdevelopedtheJSPtagextensionclasses,theydesignedthemtoworkwithJavaBeans.ThedynamicdataforapagecanbepassedasaJavaBean,andtheJSPtagcanthenusethebean’spropertiestocustomizetheoutput.Resource:/pdf/introduction-to-machine-learning/

JSP應(yīng)用框架1.1什么是應(yīng)用框架:框架(framework)是可以被重用的一種半成品的應(yīng)用程序,我們可以用它來制作專門的定制程序。這就如同人類一樣,軟件應(yīng)用的相同點要遠遠大于不同點。它們在相同的機器上運行,把信息輸入相同的設(shè)備,用相同的顯示設(shè)備顯示,并將數(shù)據(jù)村存儲到相同的硬件設(shè)備中。傳統(tǒng)的桌面開發(fā)應(yīng)用的開發(fā)人員更習(xí)慣于使用可以涵蓋應(yīng)用開發(fā)同一性的工具包和開發(fā)環(huán)境。框架提供給開發(fā)人員這些公共基礎(chǔ)上的應(yīng)用框架從而為他們的產(chǎn)品提供可重用服務(wù)的基本架構(gòu)。框架是經(jīng)典的構(gòu)建-購買-命題。如果你獨立構(gòu)建它——那當(dāng)你可以獨立完成的時候你就會理解它,但是你又花費了多長時間來用之自如呢?如果你購買了它,你必須得克服學(xué)習(xí)曲線——并且學(xué)習(xí)它將話費你大約多長時間?這里沒有明確的答案,因此許多專家會認(rèn)為,例如Struts這樣的框架能提供比全新的開發(fā)更顯著的投資回報,特別是對大型項目來說尤為顯著。1.2其它類型的框架:框架的思想不僅僅用于應(yīng)用程序也可以應(yīng)用于組件。通過這些,我們以前也提到過一些可以與在Struts一起使用的框架。其中包括Lucene搜索引擎,Scaffold工具包,Struts驗證器,以及Tiles標(biāo)簽庫等等。就像應(yīng)用框架一樣,這些工具也提供了一些可以用在用戶的定制組件之中的半成品。某些框架已經(jīng)唄限定于專門的開發(fā)環(huán)境之中。而Struts以及本文中涉及的其他框架卻不是這樣的。你可以在各種各樣的開發(fā)環(huán)境中來使用Struts:例如VisualAgeforJava,JBuilder,Eclipse,Emacs,甚至在Textpad中都可以使用Struts。只要是可以用來開發(fā)Java的工具都可以用來開發(fā)Struts。1.3使用的技術(shù):使用Struts的應(yīng)用開發(fā)基于大量的其它技術(shù)。這些技術(shù)并不專屬于Struts而是針對所有Javaweb應(yīng)用的。開發(fā)人員之所以使用Struts之類的框架的一個原因是為了隱藏在HTTP,CGI,以及JSP之類技術(shù)后面的繁瑣細(xì)節(jié)。作為一個Struts開發(fā)人員,你并不需要完全了解Struts的所有相關(guān)知識,但是它們有助于解決比較麻煩的問題。1.4超文本傳輸協(xié)議(HTTP):當(dāng)兩個國家質(zhì)檢進行交涉時,外交官們總是遵循一定的正式協(xié)議。設(shè)計外交協(xié)議的主要目的是避免誤會從而防止談判破裂。同樣,當(dāng)兩臺計算機需要進行會話時,它們也要遵循一個正式協(xié)議。這個協(xié)議定義數(shù)據(jù)如何傳輸以及到達后如何進行解碼。Web應(yīng)用程序使用HTTP協(xié)議從而在運行瀏覽器的計算機和運行的服務(wù)器的程序之間傳輸數(shù)據(jù)。很多服務(wù)器應(yīng)用程序使用HTTP之外的其他協(xié)議。這些協(xié)議中的大多數(shù)是計算機之間的持久性連接。應(yīng)用服務(wù)器可以清楚的知道是誰什么時候連接的并截止到何時中斷的連接。因為它們知道每一個連接的狀態(tài)甚至每一個使用它的人,這就是所謂的狀態(tài)協(xié)議。與此相反,HTTP被認(rèn)為是一個無狀態(tài)協(xié)議。HTTPServer可以接受來自于各種客戶的各種請求并且可以提供一些響應(yīng),即使這個響應(yīng)僅僅是一個No。沒有大量的協(xié)議和連接持久性,無狀態(tài)協(xié)議可以處理大量的請求。這就是Internet可以被數(shù)量如此巨大的計算機使用的原因之一。HTTP成為通用標(biāo)準(zhǔn)的原因之一是簡單性。一個HTTP請求看起來就像一個平常的文本文檔。這使應(yīng)用程序創(chuàng)建HTTP請求變得相當(dāng)容易。你甚至可以通過標(biāo)準(zhǔn)的程序比如說Telnet來手動發(fā)送HTTP請求。當(dāng)HTTP響應(yīng)返回時,開發(fā)人員也可以直接在文本文檔中讀到其中的內(nèi)容。HTTP請求的首行包含方法,其后是請求的來源地址和HTTP版本。可以沒有也可以有多個。HTTP頭向服務(wù)器提供額外的信息??梢园g覽器的類型和版本,可接受的文檔類型,瀏覽器的cookies,僅僅為了一個名等等。在這7種請求方法中,GET和POST是最流行的。當(dāng)服務(wù)器接收到請求,服務(wù)器會馬上產(chǎn)生一個HTTP響應(yīng)。響應(yīng)的首行稱為狀態(tài)行包含了HTTP協(xié)議的版本,字符型狀態(tài),以及該狀態(tài)的簡短描述。緊隨狀態(tài)行其后,服務(wù)器將返回一組類似于HTTP請求頭的HTTP響應(yīng)頭。按我們所描述的,HTTP并不會在請求之間保留狀態(tài)信息。服務(wù)器接受請求,發(fā)出響應(yīng),并且順利的處理文本請求。盡管HTTP是簡單與快捷的,但是無狀態(tài)的HTTP協(xié)議并不適合于需要跟蹤用戶狀態(tài)的動態(tài)應(yīng)用。Cookies和URL重寫是兩種應(yīng)用于請求之間跟蹤用戶狀態(tài)的方式。cookie是一種用戶電腦上的特殊信息包。URL重寫是在頁面地址中存儲一個特殊的標(biāo)記從而讓Java服務(wù)器可以用它來跟蹤用戶。這兩種方法都不是完美的,而且使用哪一個都意味著開發(fā)web工程時需要進行額外的工作。對其本身來說,標(biāo)準(zhǔn)的HTTPweb服務(wù)器并不需要發(fā)送動態(tài)內(nèi)容。它主要是使用請求來定位并在相應(yīng)中返回文件資源。通常這里的文件使用超文本語言(HTML)[W3C,HTML]格式化以及顯示它們。HTML頁面通常包含一些到其他頁面的超連接,或者說一些其他內(nèi)容比如圖片視頻等等。用戶點擊鏈接產(chǎn)生一個新的請求,同時開始了一個新的處理過程。標(biāo)準(zhǔn)web服務(wù)器對于靜態(tài)內(nèi)容和圖片的處理相當(dāng)好,但處理動態(tài)內(nèi)容時需要外力的幫助。定義:web中的靜態(tài)內(nèi)容直接來自于文本或數(shù)據(jù)文件,例如HTML或JPEG文件。這些文件可以隨時改變,但通過瀏覽器請求時卻不能自動改變。相反,從另一方面來說,動態(tài)內(nèi)容是臨時產(chǎn)生的,它是針對瀏覽器的一個典型的個別請求的響應(yīng)。1.5公共網(wǎng)關(guān)接口(CGI):首個廣泛使用動態(tài)內(nèi)容的標(biāo)準(zhǔn)是通用網(wǎng)關(guān)接口CommonGatewayInterface(CGI)。CGI使用環(huán)境變量,標(biāo)準(zhǔn)的輸入輸出等標(biāo)準(zhǔn)的操作系統(tǒng)特征,在Web服務(wù)器之間,以及和主機系統(tǒng)之間創(chuàng)建橋接和網(wǎng)關(guān)。其他應(yīng)用可以看到webserver傳遞過來的請求并創(chuàng)建一個定制的響應(yīng)。當(dāng)一個web服務(wù)器收到一個對CGI程序的請求時,服務(wù)器運行CGI程序并向CGI提供它請求里面所包含的信息。CGI程序開始運行后將輸出返回給web服務(wù)器。web服務(wù)器把相應(yīng)發(fā)送給瀏覽器。CGI定義了一套關(guān)于什么信息將作為環(huán)境變量傳遞以及它希望如何使用標(biāo)準(zhǔn)的輸入輸出。就像HTTP一樣,CGI是靈活和易于實現(xiàn)的,并且已經(jīng)有大量成型的CGI程序。CGI程序的主要缺點是每個請求對應(yīng)一個新副本。這是一個相對昂貴的處理方法對大容量站點來說每分鐘的數(shù)千個請求可能會使站點癱瘓。另一個缺點是依賴于平臺。為一個操作系統(tǒng)寫的CGI不能在其他操作系統(tǒng)上使用。1.6Javaservlet:Sun公司的JavaServlet平臺直接解決了CGI程序的兩個主要缺點。首先servlet比CGI程序提供更好的性能和資源利用。其次,JAVA的一次編寫,隨處運行的特性意味著servlet可以在存在虛擬機(JVM)的操作系統(tǒng)間隨意移動。Servlet類似于一個微型web服務(wù)器。它接受請求并產(chǎn)生響應(yīng)。但是,與常規(guī)web服務(wù)器不同的是,servletAPI是專門用來幫助Java開發(fā)人員創(chuàng)建動態(tài)應(yīng)用的。Servlet自身是如同其他任何一個Java類,需要編譯成字節(jié)碼文件的Java類。Servlet訪問HTTP特定服務(wù)的API,但它仍然是一個運行于程序之中的Java對象并可以利用所有的Java資產(chǎn)。為了使常規(guī)web服務(wù)器能訪問servlet,servlet被安放在一個容器中。servlet容器連接web服務(wù)器。每個servlet都可以聲明它想處理哪種URL。當(dāng)符合條件的請求到達web服務(wù)器的時候,web服務(wù)器將請求傳遞給servlet容器,servlet容器則調(diào)用servlet。但是與CGI程序不同,并不是每個請求都會創(chuàng)建新的servlet。一旦容器實例化了一個servlet,它就僅為每個新的請求創(chuàng)建一個新的線程。Java線程比CGI程序的服務(wù)器話費要少很多。一旦servlet被創(chuàng)建,使用它處理額外的請求僅帶來很小的額外開支。Servlet開發(fā)人員可以使用init()方法保持對昂貴資源的引用,比如連接數(shù)據(jù)庫或者EJBHome接口等等,以便它們可以在不同的請求之間進行共享資源。獲得這些資源需要好肥幾秒鐘的時間——這比大多數(shù)網(wǎng)上沖浪的人

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論