jsp技术网站设计外文翻译.docx

上传人:b****3 文档编号:10260959 上传时间:2023-05-24 格式:DOCX 页数:14 大小:44.31KB
下载 相关 举报
jsp技术网站设计外文翻译.docx_第1页
第1页 / 共14页
jsp技术网站设计外文翻译.docx_第2页
第2页 / 共14页
jsp技术网站设计外文翻译.docx_第3页
第3页 / 共14页
jsp技术网站设计外文翻译.docx_第4页
第4页 / 共14页
jsp技术网站设计外文翻译.docx_第5页
第5页 / 共14页
jsp技术网站设计外文翻译.docx_第6页
第6页 / 共14页
jsp技术网站设计外文翻译.docx_第7页
第7页 / 共14页
jsp技术网站设计外文翻译.docx_第8页
第8页 / 共14页
jsp技术网站设计外文翻译.docx_第9页
第9页 / 共14页
jsp技术网站设计外文翻译.docx_第10页
第10页 / 共14页
jsp技术网站设计外文翻译.docx_第11页
第11页 / 共14页
jsp技术网站设计外文翻译.docx_第12页
第12页 / 共14页
jsp技术网站设计外文翻译.docx_第13页
第13页 / 共14页
jsp技术网站设计外文翻译.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

jsp技术网站设计外文翻译.docx

《jsp技术网站设计外文翻译.docx》由会员分享,可在线阅读,更多相关《jsp技术网站设计外文翻译.docx(14页珍藏版)》请在冰点文库上搜索。

jsp技术网站设计外文翻译.docx

jsp技术网站设计外文翻译

 

外文翻译

 

工学部

工学一部

专业

网络工程

班级

B741111

学号

B74111104

姓名

王雨娉

指导教师

潘琢金

负责教师

 

沈阳航空航天大学北方科技学院

2011年6月

CombiningJSPandServlets

ThetechnologyofJSPandServletisthemostimportanttechnologywhichuseJavatechnologytoexploitrequestofserver,anditisalsothestandardwhichexploitbusinessapplication.Javadevelopersprefertouseitforavarietyofreasons,oneofwhichisalreadyfamiliarwiththeJavalanguageforthedevelopmentofthistechnologyareeasytolearnJavatotheotheris"apreparation,runeverywhere"tobringtheconceptofWebapplications,Toachievea"one-preparedeverywhererealized."Andmoreimportantly,iffollowedsomeoftheprinciplesofgooddesign,itcanbesaidofseparatingandcontenttocreatehigh-quality,reusable,easytomaintainandmodifytheapplication.Forexample,ifthedocumentinHTMLembeddedJavacodetoomuch(script),willleadthedevelopedapplicationisextremelycomplex,difficulttoread,itisnoteasyreuse,butalsoforfuturemaintenanceandmodificationwillalsocausedifficulties.Infact,CSDNtheJSP/Servletforum,canoftenseesomequestions,thecodeisverylong,canlogicisnotveryclear,alargenumberofHTMLandJavacodemixedtogether.Thisistherandomdevelopmentofthedefects.

EarlydynamicpagesmainlyCGI(CommonGatewayInterface,publicGatewayInterface)technology,youcanusedifferentlanguagesoftheCGIprograms,suchasVB,C/C++orDelphi,andsoon.ThoughthetechnologyofCGIisdevelopedandpowerful,becauseofdifficultiesinprogramming,andlowefficiency,modifycomplexshortcomings,itisgraduallybeingreplacedbythetrend.Ofallthenewtechnology,JSP/Servletwithmoreefficientandeasytoprogram,morepowerful,moresecureandhasagoodportability,theyhavebeenmanypeoplebelievethatthefutureisthemostdynamicsiteofthefuturedevelopmentoftechnology.

SimilartoCGI,Servletsupportrequest/responsemodel.Whenacustomersubmitarequesttotheserver,theserverpresentedtherequestServlet,Servletresponsibleforhandlingrequestsandgeneratearesponse,andthengavetheserver,andthenfromtheserversenttothecustomer.AndtheCGIisdifferent,Servletnotgenerateanewprocess,butwithHTTPServeratthesameprocess.Itthreadsthroughtheuseoftechnology,reducetheservercosts.Servlethandlingoftherequestprocessisthis:

Whenreceivedfromtheclient'srequest,callingservicemethods,themethodofServletarrivalofthefirstjudgementiswhattypeofrequest(GET/POST/HEAD…),thencallstheappropriatetreatment(DoGet/doPost/doHead…)andgeneratearesponse.

Althoughsuchacomplex,infact,simplysaidtoServletisaJavaclass.AndthegeneralcategoryofthedifferenceisthatthistypeoperatinginaServletcontainer,whichcanprovidesessionmanagementandtargetedlife-cyclemanagement.SothatwhenyouusetheServlet,youcangetallthebenefitsoftheJavaplatform,includingthesafetyofthemanagement,useJDBCaccessthedatabaseandcross-platformcapability.Moreover,Servletusingthread,andcandevelopmoreefficientWebapplications.

JSPtechnologyisakeyJ2EEtechnology,itatahigherlevelofabstractionofaServlet.ItallowsconventionalstaticanddynamicHTMLcontentgeneratedbycombininganHTMLpagelookslike,butasaServlettorun.TherearemanycommercialapplicationserversupportJSPtechnology,suchasBEAWebLogic,IBMWebSphere,JRun,andsoon.JSPandServletusemorethansimple.IfyouhaveaJSPsupportforWebservers,andaJSPdocument,youcanputitFangdaoanystaticHTMLfilescanbeplaced,donothavetocompile,donothavetopack,donothavetoClassPathsettings,youcanvisitasordinaryWebItdidvisit,theserverwillautomaticallyhelpyoutodootherwork.

JSPdocumentlookslikeanordinarystaticHTMLdocument,butinsidecontainsanumberofJavacode.Ituses.Jspthesuffix,usedtotelltheserverthisdocumentinneedofspecialtreatment.WhenwevisitaJSPpage,thedocumentwillfirstbetranslatedintoaJSPengineJavasourcefiles,isactuallyaServlet,andcompiler,andthen,likeotherServlet,fromServletenginetohandle.Servletengineofthistypeloading,handlingrequestsfromcustomers,andtheresultsreturnedtothecustomer,asshownbelow:

Figure1:

CallingtheprocessofJSPpages

Afteranothervisitthispagetothecustomer,aslongasthepapertherehavebeennochanges,JSPenginehasbeenloadeddirectlycalltheServlet.Ifyouhavealreadybeenmodified,itwillbeonceagaintheimplementationoftheaboveprocess,translate,compileandload.Infact,thisistheso-called"firstpersontopunishment."Becausewhenthefirstvisittotheimplementationofaseriesoftheaboveprocess,sowillspendsometimeaftersuchavisitwouldnot.

JavaservletsofferapowerfulAPIthatprovidesaccesstoalltheinformationabouttherequest,thesession,andtheapplication.combiningJSPwithservletsletsyouclearlyseparatetheapplicationlogicfromthepresentationoftheapplication;inotherwords,itletsyouusethemostappropriatecomponenttypefortherolesofModel,ViewandController.

Servlets,Filters,andListeners

AservletisaJavaclassthatextendsaserverwithfunctionalityforprocessingarequestandproducingaresponse.It'simplementedusingtheclassesandinterfacesdefinedbytheServletAPI.TheAPIconsistsoftwopackages:

thejavax.servletpackagecontainsclassesandinterfacesthatareprotocol-independent,whilethejavax.servlet.httppackageprovidesHTTP-specificextensionsandutilityclasses.

Whatmakesaservletaservletisthattheclassimplementsaninterfacenamedjavax.servlet.Servlet,eitherdirectlyorbyextendingoneofthesupportclasses.Thisinterfacedefinesthemethodsusedbythewebcontainertomanageandinteractwiththeservlet.AservletforprocessingHTTPrequeststypicallyextendsthejavax.servlet.http.HttpServletclass.ThisclassimplementstheServletinterfaceandprovidesadditionalmethodssuitableforHTTPprocessing.

ServletLifecycle

Thewebcontainermanagesallaspectsoftheservlet'slifecycle.Itcreatesaninstanceoftheservletclasswhenneeded,passesrequeststotheinstanceforprocessing,andeventuallyremovestheinstance.ForanHttpServlet,thecontainercallsthefollowingmethodsattheappropriatetimesintheservletlifecycle.

BesidesthedoGet()anddoPost()methods,therearemethodscorrespondingtotheotherHTTPmethods:

doDelete(),doHead(),doOptions(),doPut(),anddoTrace().Typicallyyoudon'timplementthesemethods;theHttpServletclassalreadytakescareofHEAD,OPTIONS,andTRACErequestsinawaythat'ssuitableformostservlets,andtheDELETEandPUTHTTPmethodsarerarelyusedinawebapplication.

It'simportanttorealizethatthecontainercreatesonlyoneinstanceofeachservlet.Thismeansthattheservletmustbethreadsafe--abletohandlemultiplerequestsatthesametime,eachexecutingasaseparatethreadthroughtheservletcode.Withoutgettinglostindetails,yousatisfythisrequirementwithregardstoinstancevariablesifyoumodifythereferencedobjectsonlyintheinit()anddestroy()methods,andjustreadthemintherequestprocessingmethods.

CompilingandInstallingaServlet

Tocompileaservlet,youmustfirstensurethatyouhavetheJARfilecontainingallServletAPIclassesintheCLASSPATHenvironmentvariable.TheJARfileisdistributedwithallwebcontainers.Tomcatincludesitinafilecalledservlet.jar,locatedinthecommon/libdirectory.OnaWindowsplatform,youincludetheJARfileintheCLASSPATH.

.ReadingaRequest

OneoftheargumentspassedtothedoGet()anddoPost()methodsisanobjectthatimplementstheHttpServletRequestinterface.Thisinterfacedefinesmethodsthatprovideaccesstoawealthofinformationabouttherequest.

GeneratingaResponse

Besidestherequestobject,thecontainerpassesanobjectthatimplementstheHttpServletResponseinterfaceasanargumenttothedoGet()anddoPost()methods.Thisinterfacedefinesmethodsforgettingawriterorstreamfortheresponsebody.Italsodefinesmethodsforsettingtheresponsestatuscodeandheaders.

UsingFiltersandListeners

Theservletspecificationdefinestwocomponenttypesbesideservlets:

filtersandlisteners.ThesetwotypeswereintroducedintheServlet2.3specification,soifyou'reusingacontainerthatdoesn'tyetsupportthisversionofthespecification,I'mafraidyou'reoutofluck.

Filters

Afilterisacomponentthatcaninterceptarequesttargetedforaservlet,JSPpage,orstaticpage,aswellastheresponsebeforeit'ssenttotheclient.Thismakesiteasytocentralizetasksthatapplytoallrequests,suchasaccesscontrol,logging,andchargingforthecontentortheservicesofferedbytheapplication.Afilterhasfullaccesstothebodyandheadersoftherequestandresponse,soitcanalsoperformvarioustransformations.OneexampleiscompressingtheresponsebodyiftheAccept-Languagerequestheaderindicatesthattheclientcanhandleacompressedresponse.

AfiltercanbeappliedtoeitheraspecificservletortoallrequestsmatchingaURLpattern,suchasURLsstartingwiththesamepathelementsorhavingthesameextension.

Listeners

Listenersallowyourapplicationtoreacttocertainevents.PriortoServlet2.3,youcouldhandleonlysessionattributebindingevents(triggeredwhenanobjectwasaddedorremovedfromasession).Youcoulddothisbylettingtheobjectsavedasasessionattribute(usingtheHttpSession.setAttribute()method)implementtheHttpSessionBindingListenerinterface.Withthenewinterfacesintr

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

当前位置:首页 > 求职职场 > 简历

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

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