外文翻译-Java和因特网_第1页
外文翻译-Java和因特网_第2页
外文翻译-Java和因特网_第3页
外文翻译-Java和因特网_第4页
外文翻译-Java和因特网_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0外文原文JavaandtheInternetIfJavais,infact,yetanothercomputerprogramminglanguage,youmayquestionwhyitissoimportantandwhyitisbeingpromotedasarevolutionarystepincomputerprogramming.Theanswerisntimmediatelyobviousifyourecomingfromatraditionalprogrammingperspective.AlthoughJavaisveryusefulforsolvingtraditionalstandaloneprogrammingproblems,itisalsoimportantbecauseitwillsolveprogrammingproblemsontheWorldWideWeb.WhatistheWeb?TheWebcanseemabitofamysteryatfirst,withallthistalkof“surfing,”“presence,”and“homepages.”Itshelpfultostepbackandseewhatitreallyis,buttodothisyoumustunderstandclient/serversystems,anotheraspectofcomputingthatsfullofconfusingissues.Client/ServercomputingTheprimaryideaofaclient/serversystemisthatyouhaveacentralrepositoryofinformationsomekindofdata,ofteninadatabasethatyouwanttodistributeondemandtosomesetofpeopleormachines.Akeytotheclient/serverconceptisthattherepositoryofinformationiscentrallylocatedsothatitcanbechangedandsothatthosechangeswillpropagateouttotheinformationconsumers.Takentogether,theinformationrepository,thesoftwarethatdistributestheinformation,andthemachine(s)wheretheinformationandsoftwareresideiscalledtheserver.Thesoftwarethatresidesontheremotemachine,communicateswiththeserver,fetchestheinformation,processesit,andthendisplaysitontheremotemachineiscalledtheclient.Thebasicconceptofclient/servercomputing,then,isnotsocomplicated.Theproblemsarisebecauseyouhaveasingleservertryingtoservemanyclientsatonce.Generally,adatabasemanagementsystemisinvolved,sothedesigner“balances”thelayoutofdataintotablesforoptimaluse.Inaddition,systemsoftenallowaclienttoinsertnewinformationintoaserver.Thismeansyoumustensurethatoneclientsnewdatadoesntwalkoveranotherclientsnewdata,orthatdataisntlostintheprocessofaddingittothedatabase(thisis1calledtransactionprocessing).Asclientsoftwarechanges,itmustbebuilt,debugged,andinstalledontheclientmachines,whichturnsouttobemorecomplicatedandexpensivethanyoumightthink.Itsespeciallyproblematictosupportmultipletypesofcomputersandoperatingsystems.Finally,therestheall-importantperformanceissue:Youmighthavehundredsofclientsmakingrequestsofyourserveratanyonetime,soanysmalldelayiscrucial.Tominimizelatency,programmersworkhardtooffloadprocessingtasks,oftentotheclientmachine,butsometimestoothermachinesattheserversite,usingso-calledmiddleware.(Middlewareisalsousedtoimprovemaintainability.)Thesimpleideaofdistributinginformationhassomanylayersofcomplexitythatthewholeproblemcanseemhopelesslyenigmatic.Andyetitscrucial:Client/servercomputingaccountsforroughlyhalfofallprogrammingactivities.Itsresponsibleforeverythingfromtakingordersandcredit-cardtransactionstothedistributionofanykindofdatastockmarket,scientific,government,younameit.Whatwevecomeupwithinthepastisindividualsolutionstoindividualproblems,inventinganewsolutioneachtime.Thesewerehardtocreateandhardtouse,andtheuserhadtolearnanewinterfaceforeachone.Theentireclient/serverproblemneedstobesolvedinabigway.TheWebasagiantserverTheWebisactuallyonegiantclient/serversystem.Itsabitworsethanthat,sinceyouhavealltheserversandclientscoexistingonasinglenetworkatonce.Youdontneedtoknowthat,becauseallyoucareaboutisconnectingtoandinteractingwithoneserveratatime(eventhoughyoumightbehoppingaroundtheworldinyoursearchforthecorrectserver).Initiallyitwasasimpleone-wayprocess.Youmadearequestofaserverandithandedyouafile,whichyourmachinesbrowsersoftware(i.e.,theclient)wouldinterpretbyformattingontoyourlocalmachine.Butinshortorderpeoplebeganwantingtodomorethanjustdeliverpagesfromaserver.Theywantedfullclient/servercapabilitysothattheclientcouldfeedinformationbacktotheserver,forexample,tododatabaselookupsontheserver,toaddnewinformationtotheserver,ortoplaceanorder(whichrequiredmoresecuritythan2theoriginalsystemsoffered).ThesearethechangeswevebeenseeinginthedevelopmentoftheWeb.TheWebbrowserwasabigstepforward:theconceptthatonepieceofinformationcouldbedisplayedonanytypeofcomputerwithoutchange.However,browserswerestillratherprimitiveandrapidlyboggeddownbythedemandsplacedonthem.Theywerentparticularlyinteractive,andtendedtoclogupboththeserverandtheInternetbecauseanytimeyouneededtodosomethingthatrequiredprogrammingyouhadtosendinformationbacktotheservertobeprocessed.Itcouldtakemanysecondsorminutestofindoutyouhadmisspelledsomethinginyourrequest.Sincethebrowserwasjustavieweritcouldntperformeventhesimplestcomputingtasks.(Ontheotherhand,itwassafe,becauseitcouldntexecuteanyprogramsonyourlocalmachinethatmightcontainbugsorviruses.)Tosolvethisproblem,differentapproacheshavebeentaken.Tobeginwith,graphicsstandardshavebeenenhancedtoallowbetteranimationandvideowithinbrowsers.Theremainderoftheproblemcanbesolvedonlybyincorporatingtheabilitytorunprogramsontheclientend,underthebrowser.Thisiscalledclient-sideprogramming.Client-sideprogrammingTheWebsinitialserver-browserdesignprovidedforinteractivecontent,buttheinteractivitywascompletelyprovidedbytheserver.Theserverproducedstaticpagesfortheclientbrowser,whichwouldsimplyinterpretanddisplaythem.BasicHyperTextMarkupLanguage(HTML)containssimplemechanismsfordatagathering:text-entryboxes,checkboxes,radioboxes,listsanddrop-downlists,aswellasabuttonthatcanonlybeprogrammedtoresetthedataontheformor“submit”thedataontheformbacktotheserver.ThissubmissionpassesthroughtheCommonGatewayInterface(CGI)providedonallWebservers.ThetextwithinthesubmissiontellsCGIwhattodowithit.Themostcommonactionistorunaprogramlocatedontheserverinadirectorythatstypicallycalled“cgi-bin.”(IfyouwatchtheaddresswindowatthetopofyourbrowserwhenyoupushabuttononaWebpage,youcansometimessee“cgi-bin”withinallthegobbledygookthere.)Theseprogramscanbewritteninmostlanguages.Perlhasbeenacommonchoicebecauseitisdesignedfortextmanipulationandisinterpreted,soitcanbeinstalledonanyserverregardlessof3processororoperatingsystem.However,Python(myfavoriteseewww.P)hasbeenmakinginroadsbecauseofitsgreaterpowerandsimplicity.ManypowerfulWebsitestodayarebuiltstrictlyonCGI,andyoucaninfactdonearlyanythingwithCGI.However,WebsitesbuiltonCGIprogramscanrapidlybecomeoverlycomplicatedtomaintain,andthereisalsotheproblemofresponsetime.TheresponseofaCGIprogramdependsonhowmuchdatamustbesent,aswellastheloadonboththeserverandtheInternet.(Ontopofthis,startingaCGIprogramtendstobeslow.)TheinitialdesignersoftheWebdidnotforeseehowrapidlythisbandwidthwouldbeexhaustedforthekindsofapplicationspeopledeveloped.Forexample,anysortofdynamicgraphingisnearlyimpossibletoperformwithconsistencybecauseaGraphicsInterchangeFormat(GIF)filemustbecreatedandmovedfromtheservertotheclientforeachversionofthegraph.Andyouvenodoubthaddirectexperiencewithsomethingassimpleasvalidatingthedataonaninputform.Youpressthesubmitbuttononapage;thedataisshippedbacktotheserver;theserverstartsaCGIprogramthatdiscoversanerror,formatsanHTMLpageinformingyouoftheerror,andthensendsthepagebacktoyou;youmustthenbackupapageandtryagain.Notonlyisthisslow,itsinelegant.Thesolutionisclient-sideprogramming.MostmachinesthatrunWebbrowsersarepowerfulenginescapableofdoingvastwork,andwiththeoriginalstaticHTMLapproachtheyaresittingthere,justidlywaitingfortheservertodishupthenextpage.Client-sideprogrammingmeansthattheWebbrowserisharnessedtodowhateverworkitcan,andtheresultfortheuserisamuchspeedierandmoreinteractiveexperienceatyourWebsite.Theproblemwithdiscussionsofclient-sideprogrammingisthattheyarentverydifferentfromdiscussionsofprogrammingingeneral.Theparametersarealmostthesame,buttheplatformisdifferent;aWebbrowserislikealimitedoperatingsystem.Intheend,youmuststillprogram,andthisaccountsforthedizzyingarrayofproblemsandsolutionsproducedbyclient-sideprogramming.Therestofthissectionprovidesanoverviewoftheissuesandapproachesinclient-sideprogramming.4Plug-insOneofthemostsignificantstepsforwardinclient-sideprogrammingisthedevelopmentoftheplug-in.Thisisawayforaprogrammertoaddnewfunctionalitytothebrowserbydownloadingapieceofcodethatplugsitselfintotheappropriatespotinthebrowser.Ittellsthebrowser“fromnowonyoucanperformthisnewactivity.”(Youneedtodownloadtheplug-inonlyonce.)Somefastandpowerfulbehaviorisaddedtobrowsersviaplug-ins,butwritingaplug-inisnotatrivialtask,andisntsomethingyoudwanttodoaspartoftheprocessofbuildingaparticularsite.Thevalueoftheplug-inforclient-sideprogrammingisthatitallowsanexpertprogrammertodevelopanewlanguageandaddthatlanguagetoabrowserwithoutthepermissionofthebrowsermanufacturer.Thus,plug-insprovidea“backdoor”thatallowsthecreationofnewclient-sideprogramminglanguages(althoughnotalllanguagesareimplementedasplug-ins).ScriptinglanguagesPlug-insresultedinanexplosionofscriptinglanguages.Withascriptinglanguage,youembedthesourcecodeforyourclient-sideprogramdirectlyintotheHTMLpage,andtheplug-inthatinterpretsthatlanguageisautomaticallyactivatedwhiletheHTMLpageisbeingdisplayed.Scriptinglanguagestendtobereasonablyeasytounderstandand,becausetheyaresimplytextthatispartofanHTMLpage,theyloadveryquicklyaspartofthesingleserverhitrequiredtoprocurethatpage.Thetrade-offisthatyourcodeisexposedforeveryonetosee(andsteal).Generally,however,youarentdoingamazinglysophisticatedthingswithscriptinglanguages,sothisisnottoomuchofahardship.ThispointsoutthatthescriptinglanguagesusedinsideWebbrowsersarereallyintendedtosolvespecifictypesofproblems,primarilythecreationofricherandmoreinteractivegraphicaluserinterfaces(GUIs).However,ascriptinglanguagemightsolve80percentoftheproblemsencounteredinclient-sideprogramming.Yourproblemsmightverywellfitcompletelywithinthat80percent,andsincescriptinglanguagescanalloweasierandfasterdevelopment,youshouldprobablyconsiderascriptinglanguagebeforelookingatamoreinvolvedsolutionsuchasJavaorActiveXprogramming.5ThemostcommonlydiscussedbrowserscriptinglanguagesareJavaScript(whichhasnothingtodowithJava;itsnamedthatwayjusttograbsomeofJavasmarketingmomentum),VBScript(whichlookslikeVisualBASIC),andTcl/Tk,whichcomesfromthepopularcross-platformGUI-buildinglanguage.Thereareothersoutthere,andnodoubtmoreindevelopment.JavaScriptisprobablythemostcommonlysupported.ItcomesbuiltintobothNetscapeNavigatorandtheMicrosoftInternetExplorer(IE).Unfortunately,theflavorofJavaScriptonthetwobrowserscanvarywidely(theMozillabrowser,freelydownloadablefromwww.M,supportstheECMAScriptstandard,whichmayonedaybecomeuniversallysupported).Inaddition,thereareprobablymoreJavaScriptbooksavailablethantherearefortheotherbrowserlanguages,andsometoolsautomaticallycreatepagesusingJavaScript.However,ifyourealreadyfluentinVisualBASICorTcl/Tk,youllbemoreproductiveusingthosescriptinglanguagesratherthanlearninganewone.(YoullhaveyourhandsfulldealingwiththeWebissuesalready.)JavaIfascriptinglanguagecansolve80percentoftheclient-sideprogrammingproblems,whatabouttheother20percentthe“reallyhardstuff?”Javaisapopularsolutionforthis.Notonlyisitapowerfulprogramminglanguagebuilttobesecure,cross-platform,andinternational,butJavaisbeingcontinuallyextendedtoprovidelanguagefeaturesandlibrariesthatelegantlyhandleproblemsthataredifficultintraditionalprogramminglanguages,suchasmultithreading,databaseaccess,networkprogramming,anddistributedcomputing.Javaallowsclient-sideprogrammingviatheappletandwithJavaWebStart.Anappletisamini-programthatwillrunonlyunderaWebbrowser.TheappletisdownloadedautomaticallyaspartofaWebpage(justas,forexample,agraphicisautomaticallydownloaded).Whentheappletisactivated,itexecutesaprogram.Thisispartofitsbeautyitprovidesyouwithawaytoautomaticallydistributetheclientsoftwarefromtheserveratthetimetheuserneedstheclientsoftware,andnosooner.Theusergetsthelatestversionoftheclientsoftwarewithoutfailandwithoutdifficultreinstallation.BecauseofthewayJavaisdesigned,theprogrammerneedstocreateonlyasingleprogram,andthat6programautomaticallyworkswithallcomputersthathavebrowserswithbuilt-inJavainterpreters.(Thissafelyincludesthevastmajorityofmachines.)SinceJavaisafull-fledgedprogramminglanguage,youcandoasmuchworkaspossibleontheclientbeforeandaftermakingrequestsoftheserver.Forexample,youwontneedtosendarequestformacrosstheInternettodiscoverthatyouvegottenadateorsomeotherparameterwrong,andyourclientcomputercanquicklydotheworkofplottingdatainsteadofwaitingfortheservertomakeaplotandshipagraphicimagebacktoyou.Notonlydoyougettheimmediatewinofspeedandresponsiveness,butthegeneralnetworktrafficandloadonserverscanbereduced,preventingtheentireInternetfromslowingdown.OneadvantageaJavaapplethasoverascriptedprogramisthatitsincompiledform,sothesourcecodeisntavailabletotheclient.Ontheotherhand,aJavaappletcanbedecompiledwithouttoomuchtrouble,buthidingyourcodeisoftennotanimportantissue.Twootherfactorscanbeimportant.Asyouwillseelaterinthisbook,acompiledJavaappletcanrequireextratimetodownload,ifitislarge.AscriptedprogramwilljustbeintegratedintotheWebpageaspartofitstext(andwillgenerallybesmallerandreduceserverhits).ThiscouldbeimportanttotheresponsivenessofyourWebsite.Anotherfactoristheall-importantlearningcurve.Regardlessofwhatyouveheard,Javaisnotatriviallanguagetolearn.IfyoureaVISUALBASICprogrammer,movingtoVBScriptwillbeyourfastestsolution(assumingyoucanconstrainyourcustomerstoWindowsplatforms),andsinceitwillprobablysolvemosttypicalclient/serverproblems,youmightbehardpressedtojustifylearningJava.IfyoureexperiencedwithascriptinglanguageyouwillcertainlybenefitfromlookingatJavaScriptorVBScriptbeforecommittingtoJava,becausetheymightfityourneedshandilyandyoullbemoreproductivesooner.SecurityAutomaticallydownloadingandrunningprogramsacrosstheInternetcansoundlikeavirus-buildersdream.IfyouclickonaWebsite,youmightautomaticallydownloadanynumberofthingsalongwiththeHTMLpage:GIFfiles,scriptcode,compiledJavacode,andActiveXcomponents.Someofthesearebenign;GIFfilescantdoanyharm,andscriptinglanguagesaregenerallylimitedinwhattheycando.Javawasalsodesignedtorunitsapplets7withina“sandbox”ofsafety,whichpreventsitfromwritingtodiskoraccessingmemoryoutsidethesandbox.MicrosoftsActiveXisattheoppositeendofthespectrum.ProgrammingwithActiveXislikeprogrammingWindowsyoucandoanythingyouwant.SoifyouclickonapagethatdownloadsanActiveXcomponent,thatcomponentmightcausedamagetothefilesonyourdisk.Ofcourse,programsthatyouloadontoyourcomputerthatarenotrestrictedtorunninginsideaWebbrowsercandothesamething.VirusesdownloadedfromBulletin-BoardSystems(BBSs)havelongbeen.Thesolutionseemstobe“digitalsignatures,”wherebycodeisverifiedtoshowwhotheauthoris.Thisisbasedontheideathatavirusworksbecauseitscreatorcanbeanonymous,soifyouremovetheanonymity,individualswillbeforcedtoberesponsiblefortheiractions.Thisseemslikeagoodplanbecauseitallowsprogramstobemuchmorefunctional,andIsuspectitwilleliminatemaliciousmischief.If,however,aprogramhasanunintentionaldestructivebug,itwillstillcauseproblems.TheJavaapproachistopreventtheseproblemsfromoccurring,viathesandbox.TheJavainterpreterthatlivesonyourlocalWebbrowserexaminestheappletforanyuntowardinstructionsastheappletisbeingloaded.Inparticular,theappletcannotwritefilestodiskorerasefiles(oneofthemainstaysofviruses).Appletsaregenerallyconsideredtobesafe,andsincethisisessentialforreliableclient/serversystems,anybugsintheJavalanguagethatallowvirusesarerapidlyrepaired.(Itsworthnotingthatthebrowsersoftwareactuallyenforcesthesesecurityrestrictions,andsomebrowsersallowyoutoselectdifferentsecuritylevelstoprovidevaryingdegreesofaccesstoyoursystem.)Youmightbeskepticalofthisratherdraconianrestrictionagainstwritingfilestoyourlocaldisk.Forexample,youmaywanttobuildalocaldatabaseorsavedataforlateruseoffline.Theinitialvisionseemedtobethateventuallyeveryonewouldgetonlinetodoanythingimportant,butthatwassoonseentobeimpractical(althoughlow-cost“Internetappliances”mightsomedaysatisfytheneedsofasignificantsegmentofusers).Thesolutionisthe“signedapplet”thatusespublic-keyencryptiontoverifythatanappletdoesindeedcomefromwhereitclaimsitdoes.Asignedappletcanstilltrashyourdisk,butthetheoryis8thatsinceyoucannowholdtheappletcreatorsaccountable,theywontdoviciousthings.Javaprovidesaframeworkfordigitalsignaturessothatyouwilleventuallybeabletoallowanapplettostepoutsidethesandboxifnecessary.Chapter14containsanexampleofhowtosignanapplet.Inaddition,JavaWebStartisarelativelynewwaytoeasilydistributestandaloneprogramsthatdontneedawebbrowserinwhichtorun.Thistechnologyhasthepotentialofsolvingmanyclientsideproblemsassociatedwithrunningprogramsinsideabrowser.WebStartprogramscaneitherbesigned,ortheycanasktheclientforpermissioneverytimetheyaredoingsomethingpotentiallydangerousonthelocalsystem.Chapter14hasasimpleexampleandexplanationofJavaWebStart.Digitalsignatureshavemissedanimportantissue,whichisthespeedthatpeoplemovearoundontheInternet.Ifyoudownloadabuggyprogramanditdoessomethinguntoward,howlongwillitbebeforeyoudiscoverthedamage?Itcouldbedaysorevenweeks.Bythen,howwillyoutrackdowntheprogramthatsdoneit?Andwhatgoodwillitdoyouatthatpoint?IranetTheWebisthemostgeneralsolutiontotheclient/serverproblem,soitmakessensetousethesametechnologytosolveasubsetoftheproblem,inparticulartheclassicclient/serverproblemwithinacompany.Withtraditionalclient/serverapproachesyouhavetheproblemofmultipletypesofclientcomputers,aswellasthedifficultyofinstallingnewclientsoftware,bothofwhicharehandilysolvedwithWebbrowsersandclient-sideprogramming.WhenWebtechnologyisusedforaninformationnetworkthatisrestrictedtoaparticularcompany,itisreferredtoasanintranet.IntranetsprovidemuchgreatersecuritythantheInternet,sinceyoucanphysicallycontrolaccesstotheserverswithinyourcompany.Intermsoftraining,itseemsthatoncepeopleunderstandthegeneralconceptofabrowseritsmucheasierforthemtodealwithdifferencesinthewaypagesandappletslook,sothelearningcurvefornewkindsofsystemsseemstobereduced.Thesecurityproblembringsustooneofthedivisionsthatseemstobeautomaticallyformingintheworldofclient-sideprogramming.IfyourprogramisrunningontheInternet,9youdontknowwhatplatformitwillbeworkingunder,andyouwanttobeextracarefulthatyoudontdisseminatebuggycode.Youneedsomethingcross-platformandsecure,likeascriptinglanguageorJava.Ifyourerunningonanintranet,youmighthaveadifferentsetofconstraints.ItsnotuncommonthatyourmachinescouldallbeIntel/Windowsplatforms.Onanintranet,youreresponsibleforthequalityofyourowncodeandcanrepairbugswhentheyredis

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论