英文文献及翻译Servlet和JSP技术简述.docx

上传人:b****1 文档编号:365532 上传时间:2023-04-29 格式:DOCX 页数:13 大小:36.58KB
下载 相关 举报
英文文献及翻译Servlet和JSP技术简述.docx_第1页
第1页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第2页
第2页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第3页
第3页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第4页
第4页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第5页
第5页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第6页
第6页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第7页
第7页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第8页
第8页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第9页
第9页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第10页
第10页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第11页
第11页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第12页
第12页 / 共13页
英文文献及翻译Servlet和JSP技术简述.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

英文文献及翻译Servlet和JSP技术简述.docx

《英文文献及翻译Servlet和JSP技术简述.docx》由会员分享,可在线阅读,更多相关《英文文献及翻译Servlet和JSP技术简述.docx(13页珍藏版)》请在冰点文库上搜索。

英文文献及翻译Servlet和JSP技术简述.docx

英文文献及翻译Servlet和JSP技术简述

AnOverviewofServletandJSPTechnology

Nagle,Wiegley

Abstract:

Servletprogramrunningintheserver-side,dynamicallygeneratedWebpagewiththetraditionalCGIandmanyothersimilarcomparedtoCGItechnology,JavaServletwithamoreefficient,easiertouse,morepowerfulandhasbetterportability,moresavingstoinvest..

Keywords:

JSPTechnology;Servlet;HTTPserver

1.AServlet'sJob

ServletsareJavaprogramsthatrunonWeborapplicationservers,actingasamiddlelayerbetweenrequestscomingfromWebbrowsersorotherHTTPclientsanddatabasesorapplicationsontheHTTPserver.Theirjobistoperformthefollowingtasks,asillustratedinFigure1-1.

Figure1-1 Webmiddlewarerole

1.1Readtheexplicitdatasentbytheclient.

TheendusernormallyentersthisdatainanHTMLformonaWebpage.However,thedatacouldalsocomefromanappletoracustomHTTPclientprogram.

1.2ReadtheimplicitHTTPrequestdatasentbythebrowser.

Figure1-1showsasinglearrowgoingfromtheclienttotheWebserver(thelayerwhereservletsandJSPexecute),buttherearereallytwovarietiesofdata:

theexplicitdatathattheenduserentersinaformandthebehind-the-scenesHTTPinformation.Bothvarietiesarecritical.TheHTTPinformationincludescookies,informationaboutmediatypesandcompressionschemesthebrowserunderstands,andsoon.

1.3Generatetheresults.

Thisprocessmayrequiretalkingtoadatabase,executinganRMIorEJBcall,invokingaWebservice,orcomputingtheresponsedirectly.Yourrealdatamaybeinarelationaldatabase.Fine.Butyourdatabaseprobablydoesn'tspeakHTTPorreturnresultsinHTML,sotheWebbrowsercan'ttalkdirectlytothedatabase.Evenifitcould,forsecurityreasons,youprobablywouldnotwantitto.Thesameargumentappliestomostotherapplications.YouneedtheWebmiddlelayertoextracttheresultsinsideadocument.

1.4Sendtheexplicitdata(i.e.,thedocument)totheclient.

Thisdocumentcanbesentinavarietyofformats,includingtext(HTMLorXML),binary(GIFimages),orevenacompressedformatlikegzipthatislayeredontopofsomeotherunderlyingformat.But,HTMLisbyfarthemostcommonformat,soanimportantservlet/JSPtaskistowraptheresultsinsideofHTML.

1.5SendtheimplicitHTTPresponsedata.

Figure1-1showsasinglearrowgoingfromtheWebmiddlelayer(theservletorJSPpage)totheclient.But,therearereallytwovarietiesofdatasent:

thedocumentitselfandthebehind-the-scenesHTTPinformation.Again,bothvarietiesarecriticaltoeffectivedevelopment.SendingHTTPresponsedatainvolvestellingthebrowserorotherclientwhattypeofdocumentisbeingreturned(e.g.,HTML),settingcookiesandcachingparameters,andothersuchtasks.

2WhyBuildWebPagesDynamically?

manyclientrequestscanbesatisfiedbyprebuiltdocuments,andtheserverwouldhandletheserequestswithoutinvokingservlets.Inmanycases,however,astaticresultisnotsufficient,andapageneedstobegeneratedforeachrequest.ThereareanumberofreasonswhyWebpagesneedtobebuilton-the-fly:

2.1TheWebpageisbasedondatasentbytheclient.

Forinstance,theresultspagefromsearchenginesandorder-confirmationpagesatonlinestoresarespecifictoparticularuserrequests.Youdon'tknowwhattodisplayuntilyoureadthedatathattheusersubmits.Justrememberthattheusersubmitstwokindsofdata:

explicit(i.e.,HTMLformdata)andimplicit(i.e.,HTTPrequestheaders).Eitherkindofinputcanbeusedtobuildtheoutputpage.Inparticular,itisquitecommontobuildauser-specificpagebasedonacookievalue.

2.2TheWebpageisderivedfromdatathatchangesfrequently.

Ifthepagechangesforeveryrequest,thenyoucertainlyneedtobuildtheresponseatrequesttime.Ifitchangesonlyperiodically,however,youcoulddoittwoways:

youcouldperiodicallybuildanewWebpageontheserver(independentlyofclientrequests),oryoucouldwaitandonlybuildthepagewhentheuserrequestsit.Therightapproachdependsonthesituation,butsometimesitismoreconvenienttodothelatter:

waitfortheuserrequest.Forexample,aweatherreportornewsheadlinessitemightbuildthepagesdynamically,perhapsreturningapreviouslybuiltpageifthatpageisstilluptodate.

2.3TheWebpageusesinformationfromcorporatedatabasesorotherserver-sidesources.

Iftheinformationisinadatabase,youneedserver-sideprocessingeveniftheclientisusingdynamicWebcontentsuchasanapplet.Imagineusinganappletbyitselfforasearchenginesite:

"Downloading50terabyteapplet,pleasewait!

"Obviously,thatissilly;youneedtotalktothedatabase.GoingfromtheclienttotheWebtiertothedatabase(athree-tierapproach)insteadoffromanappletdirectlytoadatabase(atwo-tierapproach)providesincreasedflexibilityandsecuritywithlittleornoperformancepenalty.Afterall,thedatabasecallisusuallytherate-limitingstep,sogoingthroughtheWebserverdoesnotslowthingsdown.Infact,athree-tierapproachisoftenfasterbecausethemiddletiercanperformcachingandconnectionpooling.

Inprinciple,servletsarenotrestrictedtoWeborapplicationserversthathandleHTTPrequestsbutcanbeusedforothertypesofserversaswell.Forexample,servletscouldbeembeddedinFTPormailserverstoextendtheirfunctionality.And,aservletAPIforSIP(SessionInitiationProtocol)serverswasrecentlystandardized(seehttp:

//jcp.org/en/jsr/detail?

id=116).Inpractice,however,thisuseofservletshasnotcaughton,andwe'llonlybediscussingHTTPservlets.

3TheAdvantagesofServletsOver"Traditional"CGI

Javaservletsaremoreefficient,easiertouse,morepowerful,moreportable,safer,andcheaperthantraditionalCGIandmanyalternativeCGI-liketechnologies.

3.1Efficient

WithtraditionalCGI,anewprocessisstartedforeachHTTPrequest.IftheCGIprogramitselfisrelativelyshort,theoverheadofstartingtheprocesscandominatetheexecutiontime.Withservlets,theJavavirtualmachinestaysrunningandhandleseachrequestwithalightweightJavathread,notaheavyweightoperatingsystemprocess.Similarly,intraditionalCGI,ifthereareNrequeststothesameCGIprogram,thecodefortheCGIprogramisloadedintomemoryNtimes.Withservlets,however,therewouldbeNthreads,butonlyasinglecopyoftheservletclasswouldbeloaded.Thisapproachreducesservermemoryrequirementsandsavestimebyinstantiatingfewerobjects.Finally,whenaCGIprogramfinisheshandlingarequest,theprogramterminates.Thisapproachmakesitdifficulttocachecomputations,keepdatabaseconnectionsopen,andperformotheroptimizationsthatrelyonpersistentdata.Servlets,however,remaininmemoryevenaftertheycompletearesponse,soitisstraightforwardtostorearbitrarilycomplexdatabetweenclientrequests.

3.2Convenient

ServletshaveanextensiveinfrastructureforautomaticallyparsinganddecodingHTMLformdata,readingandsettingHTTPheaders,handlingcookies,trackingsessions,andmanyothersuchhigh-levelutilities.InCGI,youhavetodomuchofthisyourself.Besides,ifyoualreadyknowtheJavaprogramminglanguage,whylearnPerltoo?

You'realreadyconvincedthatJavatechnologymakesformorereliableandreusablecodethandoesVisualBasic,VBScript,orC++.Whygobacktothoselanguagesforserver-sideprogramming?

3.3Powerful

ServletssupportseveralcapabilitiesthataredifficultorimpossibletoaccomplishwithregularCGI.ServletscantalkdirectlytotheWebserver,whereasregularCGIprogramscannot,atleastnotwithoutusingaserver-specificAPI.CommunicatingwiththeWebservermakesiteasiertotranslaterelativeURLsintoconcretepathnames,forinstance.Multipleservletscanalsosharedata,makingiteasytoimplementdatabaseconnectionpoolingandsimilarresource-sharingoptimizations.Servletscanalsomaintaininformationfromrequesttorequest,simplifyingtechniqueslikesessiontrackingandcachingofpreviouscomputations.

3.4Portable

ServletsarewrittenintheJavaprogramminglanguageandfollowastandardAPI.ServletsaresupporteddirectlyorbyapluginonvirtuallyeverymajorWebserver.Consequently,servletswrittenfor,say,MacromediaJRuncanrunvirtuallyunchangedonApacheTomcat,MicrosoftInternetInformationServer(withaseparateplugin),IBMWebSphere,iPlanetEnterpriseServer,Oracle9iAS,orStarNineWebStar.TheyarepartoftheJava2Platform,EnterpriseEdition(J2EE;seesoindustrysupportforservletsisbecomingevenmorepervasive.

3.5Inexpensive

AnumberoffreeorveryinexpensiveWebserversaregoodfordevelopmentuseordeploymentoflow-ormedium-volumeWebsites.Thus,withservletsandJSPyoucanstartwithafreeorinexpensiveserverandmigratetomoreexpensiveserverswithhigh-performancecapabilitiesoradvancedadministrationutilitiesonlyafteryourprojectmeetsinitialsuccess.ThisisincontrasttomanyoftheotherCGIalternatives,whichrequireasignificantinitialinvestmentforthepurchaseofaproprietarypackage.

Priceandportabilityaresomewhatconnected.Forexample,Martytriestokeeptrackofthecountriesofreadersthatsendhimquestionsbyemail.Indiawasnearthetopofthelist,probablybehindtheU.S.MartyalsotaughtoneofhisJSPandservlettrainingcourses(seeinManila,andtherewasgreatinterestinservletandJSPtechnologythere.

Now,whyareIndiaandthePhilippinesbothsointerested?

Wesurmisethattheansweristwofold.First,bothcountrieshavelargepoolsofwell-educatedsoftwaredevelopers.Second,both

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

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2