外文翻译---什么是ASP文件.doc
WhatisanASPFile?WithASPfiles,youcanactivateyourWebsiteusinganycombinationofHTML,scripting-suchasJavaScriptorVisualBasic®ScriptingEdition(VBScript)-andcomponentswritteninanylanguage.ThismeansyourASPfileissimplyafilethatcancontainanycombinationofHTML,scripting,andcallstocomponents.WhenyoumakeachangeontheASPfileontheserver,youneedonlysavethechangestothefilethenexttimetheWebpageisloaded,thescriptwillautomaticallybecompiled.Howdoesthishappen?ItworksbecauseASPtechnologyisbuiltdirectlyintoMicrosoftWebservers,andisthussupportedonallMicrosoftWebservers:WindowsNTInternetInformationServer(IIS)3.0,WindowsNTWorkstation,andWindows95PersonalWebServer.TheobjectmodelofASP,MicrosoftstyleHereshowitworks.WhenabrowserrequestsanASPfilefromyourWebserver,yourWebservercallsActiveServerPagestoreadthroughtheASPfile,executinganyofthecommandscontainedwithinandsendingtheresultingHTMLpagetothebrowser.AnASPfilecancontainanycombinationofHTML,script,orcommands.Thescriptcanassignvaluestovariables,requestinformationfromtheserver,orcombineanysetofcommandsintoprocedures.ASPusesthedelimiters(betterknowntoyouandmeas"thing-a-ma-bobsthatspecifythebeginningandend")"<%"and"%>"toenclosescriptcommands.Forexample,thecodebelowsetsthevalueofthevariable"MyFavTVShow"intheusercookiesto"IDreamofJeannie."<%Response.Cookies("MyFavTVShow")="IDreamofJeannie"%>ThescriptinglanguagessupportedbyASPinturnsupportuseoftheIf-Then-Elseconstruct(somethingthatwillundoubtedlywarmtheheartsofallcodersoutthere).Finally,youcanembedsomereallogicintoyourHTML.Forexample,thefollowingcodefromtheIISdocumentationshowshowyoucansetthegreetingshownbaseduponthetimeofday.<FONTCOLOR="GREEN"><%IfTime>=#12:00:00AM#AndTime<#12:00:00PM#Then%>GoodMorning!<%Else%>Hello!<%EndIf%></FONT>ImsurethatyoucanthinkofsomethingmoreinterestingforyourWebsiteIdhatetohavetocomeupwithallofthecleverideas.Built-inObjectsASPincludesfivestandardobjectsforglobaluse:RequesttogetinformationfromtheuserResponsetosendinformationtotheuserServertocontroltheInternetInformationServerSessiontostoreinformationaboutandchangesettingsfortheuserscurrentWeb-serversessionApplicationtoshareapplication-levelinformationandcontrolsettingsforthelifetimeoftheapplicationTheRequestandResponseobjectscontaincollections(bitsofinformationthatareaccessedinthesameway).Objectsusemethodstodosometypeofprocedure(ifyouknowanyobject-orientedprogramminglanguage,youknowalreadywhatamethodis)andpropertiestostoreanyoftheobjectsattributes(suchascolor,font,orsize).TheRequestobjectTheRequestobjectisusedtogetinformationfromtheuserthatispassedalonginanHTTPrequest.AsImentionedearlier,theRequestandResponseobjectssupportcollections:ClientCertificatetogetthecertificationfieldsfromtherequestissuedbytheWebbrowser.ThefieldsthatyoucanrequestarespecifiedintheX.509standardQueryStringtogettextsuchasaname,suchasmyfavoriteTVsitcomaboveFormtogetdatafromanHTMLformCookiestogetthevalueofapplication-definedcookieServerVariablestogetHTTPinformationsuchastheservernameTheResponseobjectTheResponseobjectisusedtosendinformationtotheuser.TheResponseobjectsupportsonlyCookiesasacollection(tosetcookievalues).TheResponseobjectalsosupportsanumberofpropertiesandmethods.Propertiescurrentlysupportedare:Buffersettobufferpageoutputattheserver.Whenthisissettotrue,theserverwillnotsendaresponseuntilalloftheserverscriptsonthecurrentpagehavebeenprocessed,oruntiltheFlushorEndmethodhasbeencalled.ContentTypetosetthetypeofcontent(i.e:text/HTML,Excel,etc.)Expiressetstheexpiration(whenthedataintheuserscacheforthisWebpageisconsideredinvalid)basedonminutes(i.e.:expiresin10minutes).ExpiresAbsoluteallowsyoutosettheexpirationdatetoanabsolutedateandtime.Statusreturnsthestatusline(definedintheHTTPspecificationfortheserver).ThefollowingmethodsaresupportedbytheResponseobject:AddHeaderAddsanHTMLheaderwithaspecifiedvalueAppendToLogAppendsastringtotheendoftheWebserverlogfileBinaryWritewritesbinarydata(i.e,Excelspreadsheetdata)ClearclearsanybufferedHTMLoutput.Endstopsprocessingofthescript.Flush-sendsalloftheinformationinthebuffer.RedirecttoredirecttheusertoadifferentURLWritetowriteintotheHTMLstream.ThiscanbedonebyusingtheconstructResponse.write("hello")ortheshortcutcommand<%="hello"%>TheServerobjectTheServerobjectsupportsoneproperty,ScriptTimeout,whichallowsyoutosetthevalueforwhenthescriptprocessingwilltimeout,andthefollowingmethods:CreateObjecttocreateaninstanceofaservercomponent.Thiscomponentcanbeanycomponentthatyouhaveinstalledonyourserver(suchasanActiveX).HTMLEncodetoencodethespecifiedstringinHTML.MapPathtomapthecurrentvirtualpathtoaphysicaldirectorystructure.Youcanthenpassthatpathtoacomponentthatcreatesthespecifieddirectoryorfileontheserver.URLEncodeappliesURLencodingtoaspecifiedstring.TheSessionobjectTheSessionobjectisusedtostoreinformationaboutthecurrentusersWeb-serversession.Variablesstoredwiththisobjectexistaslongastheuserssessionisactive,evenifmorethanoneapplicationisused.Thisobjectsupportsonemethod,Abandon,which(believeitornot!)abandonsthecurrentWeb-serversession,destroyinganyobjects,andsupportstwoproperties,SessionID,containingtheidentifierforthecurrentsession,andTimeout,specifyingatime-outvalueforthesession.Onethingtobearinmindaboutthesessionidentifier:ItsnotaGUID.ItsonlygoodaslongasthecurrentWeb-serversessionisrunning.IfyoushutdowntheWeb-serverservice,theidentifierswillstartalloveragain.SodontuseittocreatelogonIDs,oryoullhaveabunchofduplicatesandoneheckofaheadache.TheApplicationobjectTheApplicationobjectcanstoreinformationthatpersistsfortheentirelifetimeofanapplication(agroupofpageswithacommonroot).Generally,thisisthewholetimethattheIISserverisrunning.Thismakesitagreatplacetostoreinformationthathastoexistformorethanoneuser(suchasapagecounter).Thedownsideofthisisthatsincethisobjectisntcreatedanewforeachuser,errorsthatmaynotshowupwhenthecodeiscalledoncemayshowupwhenitiscalled10,000timesinarow.Inaddition,becausetheApplicationobjectissharedbyalltheusers,threadingcanbeanightmaretoimplement.