MostoftheleadingJavautilitiesandframeworksarenowopensourceprojects.ManyofthedevelopersworkingontheseprojectsdosoaspartoftheirregularjobswithcompanieslikeIBM,SunMicrosystems,andApple.Collaboratingopenlyonthistypeofsoftwarebenefitstheentiremarketplace.Today,manyopensourcecomponentsareintegratedintocommercialproducts.Companiesthensellprofessionaldocumentation,guaranteedsupportlevels,andothervaluableaftermarketservicestotheirclients.Whensoftwareisfreelyavailable,itbecomesmucheasierforthemarketplacetosupport.Strutsisaprimeexampleofthis.Althoughstillayoungster,ithasalreadybeenfeaturedindozensofarticlesandseminars,nottomentionbookslikethisone.Manydevelopmentteamsdonotliketousesoftwarethatwasnot“invented”in-house.Opensourcecomponentsprovideallthebenefitsofwritingthesamesoftwarein-housebutdonotlockyouintoaproprietarysolutionthatonlyyourteamunderstands.Opensourceframeworksareawin-winforeveryone.最领先的java程序和框架都是现在的开源项目。许多工作在这些项目的开发商这样做的一部分,与IBM这样的公司日常工作,太阳microsy茎,苹果。在这种类型的软件上公开合作,对整个市场都有好处。今天,许多开源组件集成到商业产品。公司然后销售专业文档,保证支持水平,以及其他有价值的售后服务给他们的客户。当软件自由地使用时,它就变得容易为市场提供支持。结构这是一个最好的例子。虽然还是个年轻人,但已经有几十篇文章和研讨会上的特色,更别提这样的书了。许多开发团队不喜欢我们没有“发明”的软件。开源组件提供了所有的好处,写在内部相同的软件,但不锁定您的专有解决方案,只有你的团队nderstands。开源框架对每个人都是一个双赢的局面。Whenmediatingtalksbetweennations,diplomatsoftenfollowaformalprotocol.Diplomaticprotocolsaredesignedtoavoidmisunderstandingsandtokeepnegotiationsfrombreakingdown.Inasimilarvein,whencomputersneedtotalk,theyalsofollowaformalprotocol.Theprotocoldefineshowdataistransmittedandhowtodecodeitonceitarrives.WebapplicationsusetheHypertextTransferProtocol(HTTP)tomovedatabetweenthebrowserrunningonyourcomputerandtheapplicationrunningontheserver.ManyserverapplicationscommunicateusingprotocolsotherthanHTTP.Someofthesemaintainanongoingconnectionbetweenthecomputers.Theapplicationserverknowsexactlywhoisconnectedatalltimesandcantellwhenaconnectionisdropped.Becausetheyknowthestateofeachconnectionandtheidentityofeachpersonusingit,theseareknownasstatefulprotocols.在国际间的对话中,外交官们经常遵循一个正式的协议。外交协议的目的是为了避免误解,防止谈判破裂。类似的在,当计算机需要交谈,他们也遵循一个正式的协议。该协议定义了如何传输数据,以及如何解码它一旦到达。Web应用程序使用超文本传输协议协议(HTTP)数据移动浏览器在您的计算机上运行的应用程序运行在服务器之间。许多服务器应用程序中使用非HTTP协议通信。一些麦山之间的电脑进行连接。应用服务器完全知道谁是连接在任何时候,可以告诉连接时,下降。因为他们知道每个人的状态,每一个使用它的人,这些被称为状态协议。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.Sun的javaServlet平台直接解决了CGI程序的两个主要缺点。首先,servlet比常规CGI程序提供更好的性能和资源利用。其次,该一次编写,到处运行javaservlet的性质意味着操作系统,java虚拟机(JVM)之间移动。Servlet看起来好像是一个小型的Web服务器。它重新接收请求并产生响应。但是,与传统的Web服务器,servlet应用程序编程接口(API)是专门设计用来帮助java开发者创建动态应用阳离子。Servlet本身是一个简单的java类被编译成字节码,像任何其他的java对象。Servlet访问HTTP特定服务的API,但它仍然是居ST的另一个java对象运行在一个应用程序,可以利用所有的java资产。给传统的Web服务器访问servlet,servlet被装入容器。servlet容器连接到网络服务器。每个servlet都可以声明哪些URL模式要处理。当请求匹配注册模式时,该网络服务器通过请求容器和容器调用servlet。但与CGI程序,一个新的servlet是不是为每个请求创建。一旦容器实例化了一个servlet,它会创建一个新的世纪为每个请求阅读。java线程比使用CGI程序的服务器进程便宜得多。一旦servlet被创建,使用额外的请求会导致非常小的开销EAD。Servlet开发人员可以使用()方法保持对昂贵资源的引用,如数据库或者EJBHome接口的连接,使它们之间可以共享的要求。获取这些资源要花费几秒钟的时间,比许多冲浪者愿意等待更长的时间。剑的另一优势是,它是多线程的,servlet开发人员必须德e特别注意确保程序是线程安全的。Tolearnmoreaboutservletprogramming,werecommendJavaServletsbyExample,byAlanR.Williamson[Williamson].要了解更多关于Servlet编程,我们推荐javaservlet实例,由艾伦·R·威廉姆森[威廉姆森]。Webdevelopersarehamperedbyadoublewebwhammy.First,weareexpectedtousewebbrowsersforclients.Second,wemustusethewebprotocoltocommunicate.WebbrowserscommunicateviaHypertextTransmissionProtocol(HTTP)anddisplaypage