资源描述:
《Servlets 和 JSP Pages最佳实践经验【外文翻译】》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、外文翻译ServletsandJSPPagesBestPracticesMaterialSource:OraclemagazineAuthor:QusayH.MahmoudJavaServlettechnologyandJavaServerPages(JSPpages)areserver-sidetechnologiesthathavedominatedtheserver-sideJavatechnologymarket,they'vebecomethestandardwaytodevelopcommercialwebapplicati
2、ons.Javadeveloperslovethesetechnologiesformyriadreasons,including:thetechnologiesarefairlyeasytolearn,andtheybringtheWriteOnce,RunAnywhereparadigmtowebapplications.Moreimportantly,ifusedeffectivelybyfollowingbestpractices,servletsandJSPpageshelpseparatepresentationfromco
3、ntent.Bestpracticesareprovenapproachesfordevelopingquality,reusable,andeasilymaintainableservletandJSPbasedwebapplications.Forinstance,embeddedJavacode(scriptlets)insectionsofHTMLdocumentscanresultincomplexapplicationsthatarenotefficient,anddifficulttoreuse,enhance,andma
4、intain.Bestpracticescanchangeallthat.Inthisarticle,I'llpresentimportantbestpracticesforservletsandJSPpages;Iassumethatyouhavebasicworkingknowledgeofbothtechnologies.Thisarticle:1Provideshints,tips,andguidelinesforworkingwith;2ervletsandJSPpages;3Providesbestpracticesfors
5、ervletsandJSPpages;1.OverviewofServletsandJSPPagesSimilartoCommonGatewayInterface(CGI)scripts,servletssupportarequestandresponseprogrammingmodel.Whenaclientsendsarequesttotheserver,theserversendstherequesttotheservlet.Theservletthenconstructsaresponsethattheserversendsba
6、cktotheclient.UnlikeCGIscripts,however,servletsrunwithinthesameprocessastheHTTPserver.Whenaclientrequestismade,theservicemethodiscalledandpassedarequestandresponseobject.TheservletfirstdetermineswhethertherequestisaGETorPOSToperation.Itthencallsoneofthefollowingmethods:d
7、oGetordoPost.ThedoGetmethodiscallediftherequestisGET,anddoPostiscallediftherequestisPOST.BothdoGetanddoPosttakerequest(HttpServletRequest)andresponse(HttpServletResponse).Inthesimplestterms,then,servletsareJavaclassesthatcangeneratedynamicHTMLcontentusingprintstatements.
8、Whatisimportanttonoteaboutservlets,however,isthattheyruninacontainer,andtheAPIsprovidesessionandobjectl