版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
外文原文JSPapplicationframeworksbrianwright、michaelfreedmanWhatareapplicationframeworks:Aframeworkisareusable,semi-completeapplicationthatcanbespecializedtoproducecustomapplications[Johnson].Likepeople,softwareapplicationsaremorealikethantheyaredifferent.Theyrunonthesamecomputers,expectinputfromthesamedevices,outputtothesamedisplays,andsavedatatothesameharddisks.Developersworkingonconventionaldesktopapplicationsareaccustomedtotoolkitsanddevelopmentenvironmentsthatleveragethesamenessbetweenapplications.Applicationframeworksbuildonthiscommongroundtoprovidedeveloperswithareusablestructurethatcanserveasthefoundationfortheirownproducts.Aframeworkprovidesdeveloperswithasetofbackbonecomponentsthathavethefollowingcharacteristics:1.Theyareknowntoworkwellinotherapplications.2.Theyarereadytousewiththenextproject.3.Theycanalsobeusedbyotherteamsintheorganization.Frameworksaretheclassicbuild-versus-buyproposition.Ifyoubuildit,youwillunderstanditwhenyouaredone—buthowlongwillitbebeforeyoucanrollyourown?Ifyoubuyit,youwillhavetoclimbthelearningcurve—andhowlongisthatgoingtotake?Thereisnorightanswerhere,butmostobserverswouldagreethatframeworkssuchasStrutsprovideasignificantreturnoninvestmentcomparedtostartingfromscratch,especiallyforlargerprojects.Othertypesofframeworks:Theideaofaframeworkappliesnotonlytoapplicationsbuttoapplicationcomponentsaswell.Throughoutthisarticle,weintroduceothertypesofframeworksthatyoucanusewithStruts.TheseincludetheLucenesearchengine,theScaffoldtoolkit,theStrutsvalidator,andtheTilestaglibrary.Likeapplicationframeworks,thesetoolsprovidesemi-completeversionsofasubsystemthatcanbespecializedtoprovideacustomcomponent.Someframeworkshavebeenlinkedtoaproprietarydevelopmentenvironment.ThisisnotthecasewithStrutsoranyoftheotherframeworksshowninthisbook.YoucanuseanydevelopmentenvironmentwithStruts:VisualAgeforJava,JBuilder,Eclipse,Emacs,andTextpadareallpopularchoicesamongStrutsdevelopers.IfyoucanuseitwithJava,youcanuseitwithStruts.Enablingtechnologies:ApplicationsdevelopedwithStrutsarebasedonanumberofenablingtechnologies.ThesecomponentsarenotspecifictoStrutsandunderlieeveryJavawebapplication.AreasonthatdevelopersuseframeworkslikeStrutsistohidethenastydetailsbehindacronymslikeHTTP,CGI,andJSP.AsaStrutsdeveloper,youdon’tneedtobeanalphabetsoupguru,butaworkingknowledgeofthesebasetechnologiescanhelpyoudevisecreativesolutionstotrickyproblems.HypertextTransferProtocol(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.(Ignoranceisnotalwaysbliss.CookiesandURLrewritingaretwocommonwaystokeeptrackofusersbetweenrequests.Acookieisaspecialpacketofinformationontheuser’scomputer.URLrewritingstoresaspecialreferenceinthepageaddressthataJavaservercanusetotrackusers.Neitherapproachisseamless,andusingeithermeansextraworkwhendevelopingawebapplication.Onitsown,astandardHTTPwebserverdoesnottrafficindynamiccontent.Itmainlyusestherequesttolocateafileandthenreturnsthatfileintheresponse.ThefileistypicallyformattedusingHypertextMarkupLanguage(HTML)[W3C,HTML]thatthewebbrowsercanformatanddisplay.TheHTMLpageoftenincludeshypertextlinkstootherwebpagesandmaydisplayanynumberofothergoodies,suchasimagesandvideos.Theuserclicksalinktomakeanotherrequest,andtheprocessbeginsanew.Standardwebservershandlestaticcontentandimagesquitewellbutneedahelpinghandtoprovideuserswithacustomized,dynamicresponse.DEFINITION:StaticcontentontheWebcomesdirectlyfromtextordatafiles,likeHTMLorJPEGfiles.Thesefilesmightbechangedfromtimetotime,buttheyarenotalteredautomaticallywhenrequestedbyawebbrowser.Dynamiccontent,ontheotherhand,isgeneratedonthefly,typicallyinresponsetoanindividualizedrequestfromabrowser.CommonGatewayInterface(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.Javaservlets: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.Tolearnmoreaboutservletprogramming,werecommendJavaServletsbyExample,byAlanR.Williamson[Williamson].ThedefinitivesourceforServletinformationistheJavaServletSpecification[Sun,JST].JavaServerPages:WhileJavaservletsareabigstepupfromCGIprograms,theyarenotapanacea.Togeneratetheresponse,developersarestillstuckwithusingprintlnstatementstorendertheHTML.Codethatlookslike:out.println("<P>OnelineofHTML.</P>");out.println("<P>AnotherlineofHTML.</P>");isalltoocommoninservletsthatgeneratetheHTTPresponse.TherearelibrariesthatcanhelpyougenerateHTML,butasapplicationsgrowmorecomplex,JavadevelopersendupbeingcastintotheroleofHTMLpagedesigners.Meanwhile,giventhechoice,mostprojectmanagersprefertodividedevelopmentteamsintospecializedgroups.TheylikeHTMLdesignerstobeworkingonthepresentationwhileJavaengineerssweatthebusinesslogic.Usingservletsaloneencouragesmixingmarkupwithbusinesslogic,makingitdifficultforteammemberstospecialize.Tosolvethisproblem,Sunturnedtotheideaofusingserverpagestocombinescriptingandtemplatingtechnologiesintoasinglecomponent.TobuildJavaServerPages,developersstartbycreatingHTMLpagesinthesameoldway,usingthesameoldHTMLsyntax.Tobringdynamiccontentintothepage,thedevelopercanalsoplaceJSPscriptingelementsonthepage.ScriptingelementsaretagsthatencapsulatelogicthatisrecognizedbytheJSP.YoucaneasilypickoutscriptingelementsonJSPpagesbylookingforcodethatbeginswith<%andendswith%>.TobeseenasaJSPpage,thefilejustneedstobesavedwithanextensionof.jsp.WhenaclientrequeststheJSPpage,thecontainertranslatesthepageintoasourcecodefileforaJavaservletandcompilesthesourceintoaJavaclassfile—justasyouwoulddoifyouwerewritingaservletfromscratch.Atruntime,thecontainercanalsocheckthelastmodifieddateoftheJSPfileagainsttheclassfile.IftheJSPfilehaschangedsinceitwaslastcompiled,thecontainerwillretranslateandrebuildthepagealloveragain.ProjectmanagerscannowassignthepresentationlayertoHTMLdevelopers,whothenpassontheirworktoJavadeveloperstocompletethebusiness-logicportion.TheimportantthingtorememberisthataJSPpageisreallyjustaservlet.Anythingyoucandowithaservlet,youcandowithaJSP.JavaBeans:JavaBeansareJavaclasseswhichconformtoasetofdesignpatternsthatmakethemeasiertousewithdevelopmenttoolsandothercomponents.DEFINITIONAJavaBeanisareusablesoftwarecomponentwritteninJava.ToqualifyasaJavaBean,theclassmustbeconcreteandpublic,andhaveanoargumentconstructor.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.ThebooleanaccessormethodsignatureforanonpropertywouldbepublicbooleanisOn()ThecanonicalmethodsignaturesplayanimportantrolewhenworkingwithJava-Beans.OthercomponentsareabletousetheJavaReflectionAPItodiscoveraJavaBean’spropertiesbylookingformethodsprefixedbyset,is,orget.IfacomponentfindssuchasignatureonaJavaBean,itknowsthatthemethodcanbeusedtoaccessorchangethebean’sproperties.SunintroducedJavaBeanstoworkwithGUIcomponents,buttheyarenowusedwitheveryaspectofJavadevelopment,includingwebapplications.WhenSunengineersdevelopedtheJSPtagextensionclasses,theydesignedthemtoworkwithJavaBeans.ThedynamicdataforapagecanbepassedasaJavaBean,andtheJSPtagcanthenusethebean’spropertiestocustomizetheoutput.FormoreonJavaBeans,wehighlyrecommendTheAwesomePowerofJavaBeans,byLawrenceH.Rodrigues[Rodrigues].ThedefinitivesourceforJavaBeaninformationistheJavaBeanSpecification[Sun,JBS].Model2:The0.92releaseoftheServlet/JSPSpecificationdescribedModel2asanarchitecturethatusesservletsandJSPpagestogetherinthesameapplication.ThetermModel2disappearedfromlaterreleases,butitremainsinpopularuseamongJavawebdevelopers.UnderModel2,servletshandlethedataaccessandnavigationalflow,whileJSPpageshandlethepresentation.Model2letsJavaengineersandHTMLdeveloperseachworkontheirownpartoftheapplication.AchangeinonepartofaModel2applicationdoesnotmandateachangetoanotherpartoftheapplication.HTMLdeveloperscanoftenchangethelookandfeelofanapplicationwithoutchanginghowtheback-officeservletswork.TheStrutsframeworkisbasedontheModel2architecture.Itprovidesacontrollerservlettohandlethenavigationalflowandspecialclassestohelpwiththedataaccess.AsubstantialcustomtaglibraryisbundledwiththeframeworktomakeStrutseasytousewithJSPpages.Summary:Inthisarticle,weintroducedStrutsasanapplicationframework.WeexaminedthetechnologybehindHTTP,theCommonGatewayInterface,Javaservlets,JSPs,andJavaBeans.WealsolookedattheModel2applicationarchitecturetoseehowitisusedtocombineservletsandJSPsinthesameapplication.NowthatyouhavehadatasteofwhatitisliketodevelopawebapplicationwithStruts,inchapter2wedigdeeperintothetheoryandpracticebehindtheStrutsarchitecture.外文翻译JSP应用框架brianwright、michaelfreedman什么是应用框架:框架(framework)是可重用,半成品应用程序,能够用来产生专门定制程序。象人一样,软件应用相同性比不一样点要多。它们运行在相同机器上,期望从相同设备输入信息,输出到相同显示设备,而且将数据存放到相同硬盘设备。开发传统桌面应用开发人员更习惯于那些能够涵盖应用开发同一性工具包和开发环境。构架在这些公共基础上应用框架能够为开发人员提供能够为他们产品提供可重用服务基础架构。框架向开发人员提供一系列具备以下特征骨架组件:1.已经知道它们在其它程序上工作得很好;2.它们随时能够在下一个项目中使用;3.它们能够被组织其它团体使用;对于框架是经典构建还是购置命题。假如你自己构建它,在你完成时你就会了解它,不过在你被融入之前又将花费多长时间呢?假如要购置,你必须得克服学习曲线,一样,在你能够用它进行工作之前又得花多长时间?这里没有所谓正确答案,但许多观察者都会同意,象Struts这么框架能提供比从头开始开发更显著投资回报,尤其是对于大型项目来说。其它类型框架:框架概念不但用于应用程序也可用于组件。在其它资料里面,我们也介绍了一些能够和Struts一起使用框架。这些包含Lucene搜索引擎,Scaffold工具包,Struts验证器,以及Tiles标签库。与应用框架一样,这些工具也提供了一些半完成版本,能够用在用户定制组件之中。一些框架被限制于专门开发环境中。Struts以及本文中包括组件却不是这么。你能够在很多环境中来开发Struts:VisualAgeforJava,JBuilder,Eclipse,Emacs,甚至使用Textpad。对于你工具,假如你能够用来开发Java,你就能够用它来开发Struts。使用技术:使用Struts应用开发使用了大量其余基础技术。这些技术并不是专门针对Struts,而是全部Javaweb应用都能够使用。开发者使用Struts之类框架是为了隐藏在诸如HTTP,CGI,以及JSP之类技术后面繁琐细节。作为一个Struts开发者,你并不需要知晓全部相关知识,不过这些基本技术工作原理可能有利于你针对棘手问题设计出创造性方案。超文本传输协议(HTTP):当两个国家之间进行调解时,外交官们总是遵照一定正式协议。外交协议主要设计来防止误解,以及预防谈判破裂。一样,当计算机间需要对话,它们也遵照一个正式协议。这个协议定义数据是怎样传输,以及它们抵达后怎样进行解码。Web应用程序就是使用HTTP协议在运行浏览器计算机和运行服务器程序间传输数据。很多服务器应用程序使用HTTP之外其余协议。他们在计算机之间维护一个持久性连接。应用服务器能够清楚知道是谁连接上来,而且何时中止连接。因为它们知道每一个连接状态,以及每一个使用它人。这称之为状态协议。相反,HTTP是一个无状态协议。HTTPServer能够接收来自于各种客户各种请求,并提供各种响应,即使是这个响应仅仅是说No。没有大量协商和连接持久性,无状态协议能够处理大量请求。这也是Internet能够扩展到很多计算机原因。HTTP成为通用标准原因是其简单性。HTTP请求看起来就像一个日常文本文档。这使应用程序很轻易创建HTTP请求。你甚至能够经过标准程序如Telnet来手动传递一个HTTP请求。当HTTP响应返回时,它也是一个开发者能够直接阅读平面文本。HTTP请求第一行包含方法,其后是请求起源地址和HTTP版本。HTTP请求头跟在首行后面,能够没有也能够有多个。HTTP头向服务器提供额外信息。能够包含浏览器种类和版本,可接收文档类型,浏览器cookies等等。7种请求方法中,GET和POST是用得最多。一旦服务器接收到请求,它就要产生一个HTTP响应。响应第一行称为状态行,包含了HTTP协议版本,数字型状态,以及状态简短描述。状态行后,服务器将返回一个HTTP响应头,类似于HTTP请求头。如上所述,HTTP并不在请求间保持状态信息。服务器接收请求,发出响应,而且继续愉快地处理文本请求。因为简单和效率,无状态协议不适合于需要跟踪用户状态动态应用。Cookies和URL重写是两个在请求间跟踪用户状态方式。cookie是一个特殊信息包,存放于用户计算机中。URL重写是在页面地址中存放一个特殊标识,Java服务器能够用它来跟踪用户。这两种方法都不是无缝,是用哪一个都意味着在开发时都要进行额外工作。对其本身来说,标准HTTPweb服务器并不传输动态内容。它主要是使用请求来定位文件资源,并在响应中返回此资源。通常这里文件使用HypertextMarkupLanguage(HTML)[W3C,HTML]格式化,以使浏览器能够显示它们。HTML页面通常包含一些到其余页面超文本连接,也能够显示其余一些内容比如图像和视频等等。用户点击连接将产生另一个请求,就开始一个新处理过程。标准web服务器处理静态内容处理得很好,但处理动态内容时则需要额外帮助伎俩了。定义静态内容直接来自于文本或数据文件,比如HTML或者JPEG文件。这些文件能够随时改变,但经过浏览器请求时,却不能自动改变。相反,动态内容是暂时产生,经典地,它是针对浏览器个别请求响应。公共网关接口(CGI):第一个普遍用来产生动态内容标准是通用网关接口(CommonGatewayInterface(CGI))。CGI使用标准操作系统特征,比如环境变量和标准输入输出,在Web服务器间以及和主机系统间创建桥接和网关。其余程序能够看到webserver传递过来请求,并创建一个定制响应。当web服务器接收到一个对CGI程序请求时,它便运行这个程序并向其提供它请求里面所包含信息。CGI程序运行,并将输出返回给Webserver,webserver则将输出响应给浏览器。CGI定义了一套关于什么信息将作为环境变量传递,以及它希望怎样使用标准输入和输出通例。与HTTP一样,CGI是灵活和易于实现,而且已经有大量现成CGI程序。CGI主要缺点是它必须为每个请求运行一个程序。这是一个相对昂贵处理方法,对大容量站点来说,每分钟有数千个请求,有可能使站点瘫痪。CGI程序另一个缺点是平台依赖性,一个平台上开发程序不一定在另一个平台上能运行。Javaservlet:Sun企业JavaServlet平台直接处理了CGI程序两个主要缺点:首先,servlet比常规CGI程序提供愈加好性能和资源利用。其次,一次编写,随地运行JAVA特征意味着servlet在有JVM操作系统间是轻便可移动。Servlet看起来好像是一个微小webserver。它接收请求并产生响应。但,和常规webserver不一样,servletAPI是专门设计来帮助Java开发人员创建动态应用。Servlet本身是要编译成字节码Java类,就像其余Java对象一样。Servlet访问HTTP特定服务API,但它依然是一个运行于程序之中Java对象,并能够利用全部Java资产。为了使常规webservers能访问servlet,servlet被安插在一个容器之中。Servlet容器连接到Web服务器。每servlet都能够申明它能够处理何种样式URL。当符合所注册样式请求抵达,webserver将请求传递给容器,容器则调用响应servlet。但和CGI程序不一样,并不是针对每个请求都要创建一个新servlet。一旦容器实例化了一个servlet,它就仅为每个新请求创建一个新线程。Java线程可比使用CGI程序服务器处理开销小多了。一旦servlet被创建,使用它处理额外请求仅带来很小额外开销。Servlet开发人员能够使用init()方法保持对昂贵资源引用,比如到数据库或者EJBHome接口连接,方便它们能够在不一样请求之间进行共享。取得这些资源要花费数秒时间,这比大多数冲浪者愿意等时间要长些。Servlet另一个好处是,它是多线程,servlet开发人员必须尤其注意确保它们servlet是线程安全。学习servlet编程,我们推荐JavaServletsbyExample,作者AlanR.Williamson[Williamson]。JavaServerPages:即使servlets对CGI程序来说前进了一大步,但它也不是万能灵药。为了产生响应,开发人员不得不使用大量println语句来生成HTML。比如这么代码:out.println("<P>OnelineofHTML.</P>");out.println("<P>AnotherlineofHTML.</P>");在产生HTTP响应Servlet中是很普遍。也有一些库有利于你产生HTML。伴随应用越来越复杂,Java开发人员将不再饰演HTML页面设计角色。同时,大多数项目经理更喜欢将团体分成不一样小组。它们喜欢HTML设计人员处理表现层工作,而Java工程师则专注于业务逻辑。单独使用servlet做法激励混合标识和业务逻辑,极难区分团体人员专业工作。为处理这个问题,Sun提出了一个将脚本和模板技术结合到一个组件中服务器页面技术(JavaServerPages)。为创建JSP页面,开发者按创建HTML页面类似方式创建页面,使用相同HTML语法
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 右脚踝扭伤宣教
- 门诊部科普小知识
- 住院病人探视宣教
- 骨质疏松宣教手册
- 八旗制度管理员工培训
- 苏课新版八年级生物上册月考考试试题及答案
- 劳务外包协议书范本
- 债务转让协议书怎么写
- 暑假消防教育课件
- 心身疾病护理科普
- 湖南省部分校2025-2026学年高二上学期10月联考语文试题(含答案)(解析版)
- 2025贵州惠水县选聘城市社区工作者3人考试模拟试题及答案解析
- 大学高等数学上习题附答案
- 生产车间现场管理规定
- DB54∕T 0298-2023 电梯使用安全标志与标识
- 机场停机坪地坪施工方案
- 5.15中国工农红军长征与遵义会议教学设计-统编版八年级历史上册
- 2025年成人高考高升专试题(含答案)
- 委托物流运输代理服务合同
- 国际工程总承包合同范本比较:条款、应用与优化策略
- 餐饮督导运营培训课件
评论
0/150
提交评论