本科毕业设计关于java技术外文翻译.docx
《本科毕业设计关于java技术外文翻译.docx》由会员分享,可在线阅读,更多相关《本科毕业设计关于java技术外文翻译.docx(26页珍藏版)》请在冰点文库上搜索。
![本科毕业设计关于java技术外文翻译.docx](https://file1.bingdoc.com/fileroot1/2023-7/7/02778e79-21ce-4d46-b58c-e354c9d39cef/02778e79-21ce-4d46-b58c-e354c9d39cef1.gif)
本科毕业设计关于java技术外文翻译
附录一外文资料原文:
ABOUTJAVATECHNOLOGY
ServletsandJSP:
AnOverview
1.WhatareJavaServlets?
ServletsareJavatechnology'sanswertoCGIprogramming.TheyareprogramsthatrunonaWebserverandbuildWebpages.BuildingWebpagesontheflyisuseful(andcommonlydone)foranumberofreasons:
∙TheWebpageisbasedondatasubmittedbytheuser.Forexampletheresultspagesfromsearchenginesaregeneratedthisway,andprogramsthatprocessordersfore-commercesitesdothisaswell.
∙Thedatachangesfrequently.Forexample,aweather-reportornewsheadlinespagemightbuildthepagedynamically,perhapsreturningapreviouslybuiltpageifitisstilluptodate.
∙TheWebpageusesinformationfromcorporatedatabasesorothersuchsources.Forexample,youwouldusethisformakingaWebpageatanon-linestorethatlistscurrentpricesandnumberofitemsinstock.
2.WhataretheAdvantageofServletsOver"Traditional"CGI?
Javaservletsaremoreefficient,easiertouse,morepowerful,moreportable,andcheaperthantraditionalCGIandthanmanyalternativeCGI-liketechnologies.(Moreimportantly,servletdevelopersgetpaidmorethanPerlprogrammers:
-).
∙Efficient.WithtraditionalCGI,anewprocessisstartedforeachHTTPrequest.IftheCGIprogramdoesarelativelyfastoperation,theoverheadofstartingtheprocesscandominatetheexecutiontime.Withservlets,theJavaVirtualMachinestaysup,andeachrequestishandledbyalightweightJavathread,notaheavyweightoperatingsystemprocess.Similarly,intraditionalCGI,ifthereareNsimultaneousrequesttothesameCGIprogram,thenthecodefortheCGIprogramisloadedintomemoryNtimes.Withservlets,however,thereareNthreadsbutonlyasinglecopyoftheservletclass.ServletsalsohavemorealternativesthandoregularCGIprogramsforoptimizationssuchascachingpreviouscomputations,keepingdatabaseconnectionsopen,andthelike.
∙Convenient.Hey,youalreadyknowJava.WhylearnPerltoo?
Besidestheconvenienceofbeingabletouseafamiliarlanguage,servletshaveanextensiveinfrastructureforautomaticallyparsinganddecodingHTMLformdata,readingandsettingHTTPheaders,handlingcookies,trackingsessions,andmanyothersuchutilities.
∙Powerful.JavaservletsletyoueasilydoseveralthingsthataredifficultorimpossiblewithregularCGI.Foronething,servletscantalkdirectlytotheWebserver(regularCGIprogramscan't).Thissimplifiesoperationsthatneedtolookupimagesandotherdatastoredinstandardplaces.Servletscanalsosharedataamongeachother,makingusefulthingslikedatabaseconnectionpoolseasytoimplement.Theycanalsomaintaininformationfromrequesttorequest,simplifyingthingslikesessiontrackingandcachingofpreviouscomputations.
∙Portable.ServletsarewritteninJavaandfollowawell-standardizedAPI.Consequently,servletswrittenfor,sayI-PlanetEnterpriseServercanrunvirtuallyunchangedonApache,MicrosoftIIS,orWebStar.ServletsaresupporteddirectlyorviaapluginonalmosteverymajorWebserver.
∙Inexpensive.ThereareanumberoffreeorveryinexpensiveWebserversavailablethataregoodfor"personal"useorlow-volumeWebsites.However,withthemajorexceptionofApache,whichisfree,mostcommercial-qualityWebserversarerelativelyexpensive.Nevertheless,onceyouhaveaWebserver,nomatterthecostofthatserver,addingservletsupporttoit(ifitdoesn'tcomepreconfiguredtosupportservlets)isgenerallyfreeorcheap.
3.WhatisJSP?
JavaServerPages(JSP)isatechnologythatletsyoumixregular,staticHTMLwithdynamically-generatedHTML.ManyWebpagesthatarebuiltbyCGIprogramsaremostlystatic,withthedynamicpartlimitedtoafewsmalllocations.ButmostCGIvariations,includingservlets,makeyougeneratetheentirepageviayourprogram,eventhoughmostofitisalwaysthesame.JSPletsyoucreatethetwopartsseparately.Here'sanexample:
DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
WelcometoOurStoreWelcometoOurStore
Welcome,
--Usernameis"NewUser"forfirst-timevisitors-->
<%out.println(Utils.getUserNameFromCookie(request));%>
Toaccessyouraccountsettings,click
here.
RegularHTMLforalltherestoftheon-linestore'sWebpage.
4.WhataretheAdvantagesofJSP?
∙vs.ActiveServerPages(ASP).ASPisasimilartechnologyfromMicrosoft.TheadvantagesofJSParetwofold.First,thedynamicpartiswritteninJava,notVisualBasicorotherMS-specificlanguage,soitismorepowerfulandeasiertouse.Second,itisportabletootheroperatingsystemsandnon-MicrosoftWebservers.
∙vs.PureServlets.JSPdoesn'tgiveyouanythingthatyoucouldn'tinprincipledowithaservlet.Butitismoreconvenienttowrite(andtomodify!
)regularHTMLthantohaveazillionprintlnstatementsthatgeneratetheHTML.Plus,byseparatingthelookfromthecontentyoucanputdifferentpeopleondifferenttasks:
yourWebpagedesignexpertscanbuildtheHTML,leavingplacesforyourservletprogrammerstoinsertthedynamiccontent.
∙vs.Server-SideIncludes(SSI).SSIisawidely-supportedtechnologyforincludingexternally-definedpiecesintoastaticWebpage.JSPisbetterbecauseitletsyouuseservletsinsteadofaseparateprogramtogeneratethatdynamicpart.Besides,SSIisreallyonlyintendedforsimpleinclusions,notfor"real"programsthatuseformdata,makedatabaseconnections,andthelike.
∙vs.JavaScript.JavaScriptcangenerateHTMLdynamicallyontheclient.Thisisausefulcapability,butonlyhandlessituationswherethedynamicinformationisbasedontheclient'senvironment.Withtheexceptionofcookies,HTTPandformsubmissiondataisnotavailabletoJavaScript.And,sinceitrunsontheclient,JavaScriptcan'taccessserver-sideresourceslikedatabases,catalogs,pricinginformation,andthelike.
∙vs.StaticHTML.RegularHTML,ofcourse,cannotcontaindynamicinformation.JSPissoeasyandconvenientthatitisquitefeasibletoaugmentHTMLpagesthatonlybenefitmarginallybytheinsertionofsmallamountsofdynamicdata.Previously,thecostofusingdynamicdatawouldprecludeitsuseinallbutthemostvaluableinstances.
Overview
JavaServerPages(JSP)letsyouseparatethedynamicpartofyourpagesfromthestaticHTML.YousimplywritetheregularHTMLinthenormalmanner,usingwhateverWeb-page-buildingtoolsyounormallyuse.Youthenenclosethecodeforthedynamicpartsinspecialtags,mostofwhichstartwith"<%"andendwith"%>".Forexample,hereisasectionofaJSPpagethatresultsinsomethinglike"ThanksfororderingCoreWebProgramming"forURLofhttp:
//host/OrderConfirmation.jsp?
title=Core+Web+Programming:
Thanksfororderinga
<%=request.getParameter("title")%>
Younormallygiveyourfilea.jspextension,andtypicallyinstallitinanyplaceyoucouldplaceanormalWebpage.AlthoughwhatyouwriteoftenlooksmorelikearegularHTMLfilethanaservlet,behindthescenes,theJSPpagejustgetsconvertedtoanormalservlet,withthestaticHTMLsimplybeingprintedtotheoutputstreamassociatedwiththeservlet'sservicemethod.Thisisnormallydonethefirsttimethepageisrequested,anddeveloperscansimplyrequestthepagethemselveswhenfirstinstallingitiftheywanttobesurethatthefirstrealuserdoesn'tgetamomentarydelaywhentheJSPpageistranslatedtoaservletandtheservletiscompiledandloaded.NotealsothatmanyWebserversletyoudefinealiasesthatsothataURLthatappearstoreferenceanHTMLfilereallypointstoaservletorJSPpage.
AsidefromtheregularHTML,therearethreemaintypesofJSPconstructsthatyouembedinapage:
scriptingelements,directives,andactions.ScriptingelementsletyouspecifyJavacodethatwillbecomepartoftheresultantservlet,directivesletyoucontroltheoverallstructureoftheservlet,andactionsletyouspecifyexistingcomponentsthatshouldbeused,andotherwisecontrolthebehavioroftheJSPengine.Tosimplifythescriptingelements,youhaveaccesstoanumberofpredefinedvariablessuchasrequestinthesnippetabove.
Notethatthistutorialcoversversion1.0oftheJSPspecification.JSPhaschangeddramaticallysinceversion0.92,andalthoughthesechangeswerealmostentirelyforthebetter,youshouldnotethatversion1.0JSPpagesarealmosttotallyincompatiblewiththeearlierJSPengines.
2.SyntaxSummary
JSPElement
Syntax
Interpretation
Notes
JSPExpression
<%=expression%>
Expressionisevaluatedandplacedinoutput.
XMLequivalentis
expression>
expression
expression>.Predefinedvariablesarerequest,response,out,session,application,config,andpageContext(availableinscriptletsalso).
JSPScriptlet
<%code%>
Codeisinsertedinservicemethod.
XMLequivalentis
scriptlet>
code
scriptlet>.
JSPDeclaration
<%!
code%>
Codeisinsertedinbodyofservletclass,outsideofservicemethod.
XMLequivalentis
declaration>
code
declaration>.
JSPpageDirective
<%@pageatt="val"%>
Directionstotheservletengineaboutgeneralsetup.
XMLequivalentis
directive.page att="val"\>.Legalattributes,withdefaultvaluesinbold,are:
∙import="package.class"
∙contentType="MIME-Type"
∙isThreadSafe="true|false"
∙session="true|false"
∙buffer="sizekb|none"
∙autoflush="true|false"
∙extends="package.class"
∙info="message"
∙errorPage="url"
∙isErrorPage="true|false"
∙language="java"
JSPincludeDirective
<%@inclu