《JSP技术----外文文献(共9页).docx》由会员分享,可在线阅读,更多相关《JSP技术----外文文献(共9页).docx(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上外文文献JSPTechnology andServletsJSP profileJSP(JavaServerPages)isinitiatedbySunMicrosystems,Inc.,withmanycompaniestoparticipateintheestablishmentofadynamicwebpagetechnicalstandards.JSPtechnologysomewhatsimilartoASPtechnology,itisinthetraditionalHTMLwebpagedocument(*.htm,*.html)toinserttheJ
2、avaprogrammingparagraph(Scriptlet)andJSPtag(tag),thusJSPdocuments(*.jsp).UsingJSPdevelopmentoftheWebapplicationiscrossthatcanrunonLinux,isalsoavailableforotheroperatingsystems.JSPtechnologytousetheJavaprogramminglanguagepreparedbythecategoryofXMLtagsandscriptlets,toproducedynamicpagespackageprocessi
3、nglogic.Pagealsovisitbytagsandscriptletsexistintheservicessideoftheresourcesoflogic.JSPpagelogicandwebpagedesignanddisplayseparation,supportreusablecomponent-baseddesign,Web-basedapplicationdevelopmentisrapidandeasy.WebserverinthefaceofvisitsJSPpagerequest,thefirstimplementationoftheproceduresof,and
4、thentogetherwiththeresultsoftheimplementationofJSPdocumentsinHTMLcodewiththereturntothecustomer.InserttheJavaprogrammingoperationofthedatabasecanbereorientedwebsites,inordertoachievetheestablishmentofdynamicpagesneededtofunction.JSPandJavaServlet,isintheimplementationoftheserver,usuallyreturnedtothe
5、clientisanHTMLtext,aslongastheclientbrowserwillbeabletovisit.JSP1.0specificationofthefinalversionislaunchedinSeptember1999,Decemberhasintroduced1.1specifications.AtpresentrelativelynewisJSP1.2norms,JSP2.0normsofthedrafthasalsobeenintroduced.JSPpagesfromHTMLcodeandJavacodeembeddedinoneofthecomponents
6、.JSscriptlanguagesynopsisJSisjavascrip,JavascriptisonekindthescriptlanguagewhichcomesbytheNetscapeLiveScriptdevelopment,themainpurposeistosolvetheserverterminallanguage,forinstancePerl,carry-overspeedquestion.Atthattimeservedtheendtoneedtocarryontheconfirmationtothedata,becausethenetworkspeedwasquit
7、eslow,onlythen28.8kbps,theconfirmationstepwastestimeweretoomany.ThereforeNetscapebrowserNavigatorhasjoinedJavascript,hasprovidedthedataconfirmationbasicfunction.TheJavaScriptofficialnameis“ECMAScript”.ThisstandardbyECMAorganizationdevelopmentandmaintenance.ECMA262istheofficialJavaScriptstandard.This
8、standardbasedonJavaScript(Netscape)andJScript(Microsoft).Netscape(Navigator2.0)BrendanEichhasinventedthislanguage,startedfrom1996,alreadyappearedinallNetscapeandintheMicrosoftbrowser.TheECMA262developmentbeganin1996,in1997July,theECMAgeneralmeetinghasaccepteditsfirstedition.Thescriptusesonespecificd
9、escriptivelanguage,restsoncertainformcompilationtobepossibletheexecutiondocument,isalsocalledasgreatorthebatchrundocument.Thescriptusuallymaytransfertemporarilybytheapplicationprocedureandcarryout.Eachkindofscriptpresentwidelyisappliedinthehomepagedesign,becausethescriptnotonlymayreducethehomepageth
10、escaleandraisesthehomepagebrowsingspeed,moreovermayenrichthehomepageperformance,likeanimation,soundandsoon.Citesamostcommonexample,whenweclickinthehomepagetheEmailaddresscantransferOutlookExpressortheFoxmailthiskindofmailsoftwareautomatically,isrealizesthroughthescriptfunction.Alsobecauseofscriptthe
11、secharacteristics,thehumanwhoharborsulteriormotivesbysomeareoftenusing.Forexamplejoinssomedestructioncomputersystemsorderinthescript,likethisworksastheuserbrowsinghomepage,oncetransfersthiskindofscript,willthencausetheuserthesystemtocomeundertheattack.Thereforetheusershouldactaccordingtovisitshomepa
12、gethetrustdegreeselectivesecurityrank,speciallyregardingtheseitselfcontentontheillegalhomepage,donotpermittheusescripteasily.Through“thesafeestablishment”thedialogbox,thechoice“thescript”underoptioneachkindofestablishmentmaywitheaserealizetoscriptbeingforbidandbeginsusing.JSPandServletsThetechnology
13、ofJSPandServletisthemostimportanttechnologywhichuseJavatechnologytoexploitrequestofserver,anditisalsothestandardwhichexploitbusinessapplication.Javadevelopersprefertouseitforavarietyofreasons,oneofwhichisalreadyfamiliarwiththeJavalanguageforthedevelopmentofthistechnologyareeasytolearnJavatotheotheri
14、sapreparation,runeverywheretobringtheconceptofWebapplications,Toachieveaone-preparedeverywhererealized.Andmoreimportantly,iffollowedsomeoftheprinciplesofgooddesign,itcanbesaidofseparatingandcontenttocreatehigh-quality,reusable,easytomaintainandmodifytheapplication.Forexample,ifthedocumentinHTMLembed
15、dedJavacodetoomuch(script),willleadthedevelopedapplicationisextremelycomplex,difficulttoread,itisnoteasyreuse,butalsoforfuturemaintenanceandmodificationwillalsocausedifficulties.Infact,CSDNtheJSP/Servletforum,canoftenseesomequestions,thecodeisverylong,canlogicisnotveryclear,alargenumberofHTMLandJava
16、codemixedtogether.Thisistherandomdevelopmentofthedefects.EarlydynamicpagesmainlyCGI(CommonGatewayInterface,publicGatewayInterface)technology,youcanusedifferentlanguagesoftheCGIprograms,suchasVB,C/C+orDelphi,andsoon.ThoughthetechnologyofCGIisdevelopedandpowerful,becauseofdifficultiesinprogramming,and
17、lowefficiency,modifycomplexshortcomings,itisgraduallybeingreplacedbythetrend.Ofallthenewtechnology,JSP/Servletwithmoreefficientandeasytoprogram,morepowerful,moresecureandhasagoodportability,theyhavebeenmanypeoplebelievethatthefutureisthemostdynamicsiteofthefuturedevelopmentoftechnology.SimilartoCGI,
18、Servletsupportrequest/responsemodel.Whenacustomersubmitarequesttotheserver,theserverpresentedtherequestServlet,Servletresponsibleforhandlingrequestsandgeneratearesponse,andthengavetheserver,andthenfromtheserversenttothecustomer.AndtheCGIisdifferent,Servletnotgenerateanewprocess,butwithHTTPServeratth
19、esameprocess.Itthreadsthroughtheuseoftechnology,reducetheservercosts.Servlethandlingoftherequestprocessisthis:Whenreceivedfromtheclientsrequest,callingservicemethods,themethodofServletarrivalofthefirstjudgementiswhattypeofrequest(GET/POST/HEAD),thencallstheappropriatetreatment(DoGet/doPost/doHead)an
20、dgeneratearesponse.Althoughsuchacomplex,infact,simplysaidtoServletisaJavaclass.AndthegeneralcategoryofthedifferenceisthatthistypeoperatinginaServletcontainer,whichcanprovidesessionmanagementandtargetedlifecyclemanagement.SothatwhenyouusetheServlet,youcangetallthebenefitsoftheJavaplatform,includingth
21、esafetyofthemanagement,useJDBCaccessthedatabaseandcrossplatformcapability.Moreover,Servletusingthread,andcandevelopmoreefficientWebapplications.JSPtechnologyisakeyJ2EEtechnology,itatahigherlevelofabstractionofaServlet.ItallowsconventionalstaticanddynamicHTMLcontentgeneratedbycombininganHTMLpagelooks
22、like,butasaServlettorun.TherearemanycommercialapplicationserversupportJSPtechnology,suchasBEAWebLogic,IBMWebSphere,JRun,andsoon.JSPandServletusemorethansimple.IfyouhaveaJSPsupportforWebservers,andaJSPdocument,youcanputitFangdaoanystaticHTMLfilescanbeplaced,donothavetocompile,donothavetopack,donothav
23、etoClassPathsettings,youcanvisitasordinaryWebItdidvisit,theserverwillautomaticallyhelpyoutodootherwork.JSPdocumentlookslikeanordinarystaticHTMLdocument,butinsidecontainsanumberofJavacode.Ituses.Jspthesuffix,usedtotelltheserverthisdocumentinneedofspecialtreatment.WhenwevisitaJSPpage,thedocumentwillfi
24、rstbetranslatedintoaJSPengineJavasourcefiles,isactuallyaServlet,andcompiler,andthen,likeotherServlet,fromServletenginetohandle.Servletengineofthistypeloading,handlingrequestsfromcustomers,andtheresultsreturnedtothecustomer.Afteranothervisitthispagetothecustomer,aslongasthepapertherehavebeennochanges
25、,JSPenginehasbeenloadeddirectlycalltheServlet.Ifyouhavealreadybeenmodified,itwillbeonceagaintheimplementationoftheaboveprocess,translate,compileandload.Infact,thisistheso-calledfirstpersontopunishment.Becausewhenthefirstvisittotheimplementationofaseriesoftheaboveprocess,sowillspendsometimeaftersucha
26、visitwouldnot.JavaservletsofferapowerfulAPIthatprovidesaccesstoalltheinformationabouttherequest,thesession,biningJSPwithservletsletsyouclearlyseparatetheapplicationlogicfromthepresentationoftheapplication;inotherwords,itletsyouusethemostappropriatecomponenttypefortherolesofModel,ViewandController.Se
27、rvlets,Filters,andListenersAservletisaJavaclassthatextendsaserverwithfunctionalityforprocessingarequestandproducingaresponse.ItsimplementedusingtheclassesandinterfacesdefinedbytheServletAPI.TheAPIconsistsoftwopackages:thejavax.servletpackagecontainsclassesandinterfacesthatareprotocolindependent,whil
28、ethejavax.servlet.httppackageprovidesHTTP-specificextensionsandutilityclasses.Whatmakesaservletaservletisthattheclassimplementsaninterfacenamedjavax.servlet.Servlet,eitherdirectlyorbyextendingoneofthesupportclasses.Thisinterfacedefinesthemethodsusedbythewebcontainertomanageandinteractwiththe servlet
29、.AservletforprocessingHTTPrequeststypicallyextendsthejavax.servlet.http.HttpServletclass.ThisclassimplementstheServletinterfaceandprovidesadditionalmethodssuitableforHTTPprocessing.ServletLifecycleThewebcontainermanagesallaspectsoftheservletslifecycle.Itcreatesaninstanceoftheservletclasswhenneeded,p
30、assesrequeststotheinstanceforprocessing,andeventuallyremovestheinstance.ForanHttpServlet,thecontainercallsthefollowingmethodsattheappropriatetimesintheservletlifecycle.BesidesthedoGet()anddoPost()methods,therearemethodscorrespondingtotheotherHTTPmethods:doDelete(),doHead(),doOptions(),doPut(),anddoT
31、race().Typicallyyoudontimplementthesemethods;theHttpServletclassalreadytakescareofHEAD,OPTIONS,andTRACErequestsinawaythatssuitableformostservlets,andtheDELETEandPUTHTTPmethodsarerarelyusedinawebapplication.Itsimportanttorealizethatthecontainercreatesonlyoneinstanceofeachservlet.Thismeansthattheservl
32、etmustbethreadsafe-abletohandlemultiplerequestsatthesametime,eachexecutingasaseparatethreadthroughtheservletcode.Withoutgettinglostindetails,yousatisfythisrequirementwithregardstoinstancevariablesifyoumodifythereferencedobjectsonlyintheinit()anddestroy()methods,andjustreadthemintherequestprocessingm
33、ethods.CompilingandInstallingaServletTocompileaservlet,youmustfirstensurethatyouhavetheJARfilecontainingallServletAPIclassesintheCLASSPATHenvironmentvariable.TheJARfileisdistributedwithallwebcontainers.Tomcatincludesitinafilecalledservlet.jar,locatedinthecommon/libdirectory.OnaWindowsplatform,youinc
34、ludetheJARfileintheCLASSPATH.ReadingaRequestOneoftheargumentspassedtothedoGet()anddoPost()methodsisanobjectthatimplementstheHttpServletRequestinterface.Thisinterfacedefinesmethodsthatprovideaccesstoawealthofinformationabouttherequest.GeneratingaResponseBesidestherequestobject,thecontainerpassesanobj
35、ectthatimplementstheHttpServletResponseinterfaceasanargumenttothedoGet()anddoPost()methods.Thisinterfacedefinesmethodsforgettingawriterorstreamfortheresponsebody.Italsodefinesmethodsforsettingtheresponsestatuscodeandheaders.UsingFiltersandListenersTheservletspecificationdefinestwocomponenttypesbesid
36、eservlets:filtersandlisteners.ThesetwotypeswereintroducedintheServlet2.3specification,soifyoureusingacontainerthatdoesntyetsupportthisversionofthespecification,Imafraidyoure outofluck.FiltersAfilterisacomponentthatcaninterceptarequesttargetedforaservlet,JSPpage,orstaticpage,aswellastheresponsebefore
37、itssenttotheclient.Thismakesiteasytocentralizetasksthatapplytoallrequests,suchasaccesscontrol,logging,andchargingforthecontentortheservicesofferedbytheapplication.Afilterhasfullaccesstothebodyandheadersoftherequestandresponse,soitcanalsoperformvarioustransformations.Oneexampleiscompressingtherespons
38、ebodyifthe Acceptlanguagerequestheaderindicatesthattheclientcanhandleacompressedresponse.AfiltercanbeappliedtoeitheraspecificservletortoallrequestsmatchingaURLpattern,suchasURLsstartingwiththesamepathelementsorhavingthesameextension.ListenersListenersallowyourapplicationtoreacttocertainevents.Priort
39、oServlet2.3,youcouldhandleonlysessionattributebindingevents(triggeredwhenanobjectwasaddedorremovedfromasession).Youcoulddothisbylettingtheobjectsavedasasessionattributimplementthe HttpSessionBindingListenerinterface.Withthenewinterfacesintroducedinthe2.3versionofthespecification,youcancreatelistener
40、sforservletcontextandsessionlifecycleeventsaswellassessionactivationandpassivationevents(usedbyacontainerthattemporarilysavessessionstatetodiskormigratesasessiontoanotherserver).Anewsessionattributeeventlisteneralsomakesitpossibletodealwithattributebindingeventsforallsessionsinoneplace,insteadofplac
41、ingindividuallistenerobjectsineachsession.ThenewtypesoflistenersfollowthestandardJavaeventmodel.Inotherwords,alistenerisaclassthatimplementsoneormoreofthelistenerinterfaces.Theinterfacesdefinemethodsthatcorrespondtoevents.Thelistenerclassisregisteredwiththecontainerwhentheapplicationstarts,andthecontainerthencallstheeventmethodsattheappropriatetimes.InitializingSharedResourcesUsingaListenerBeanslikethistypicallyneedtobeinitializedbeforetheycanbeused.Forin