zl程序教程

您现在的位置是:首页 >  硬件

当前栏目

javascriptasp教程服务器对象

服务器教程对象 javascriptasp
2023-06-13 09:13:53 时间

Overview:

TheServerObjecthasseven(7)Methods,one(1)Property,zero(0)Events,andzero(0)Collections.

ListofMethods:

ServerMethods CreateObject() Server.CreateObject("ADODB.Recordset")
CreateaninstanceofanObject Execute() Server.Execute("fileName.asp")
Executesanoutsidefile(effectissimilartoSSI) GetLastError() Server.GetLastError()
ReturnslocationanddescriptionofthelastASPerror HTMLEncode() Server.HTMLEncode("someString")
EncodesstringtoHTMLcharacters MapPath() Server.MapPath("\\virtualFolder")
Convertsvirtualpathtophysicalpath Transfer() Server.Transfer("fileName.asp")
Transfersexecutionoutofonepageandintoanother URLEncode() Server.URLEncode("someString")
EncodesstringtoURLstandards

BelowisthescriptforLesson14.

<%@LANGUAGE="JavaScript"%>
<HTML>
<BODY>
<%=Server.URLEncode("Hello,thisstringisURLEncoded!")%>
<BR><BR>
Nowlet"sseeareprintofScript14a.asp.
Ididnottypeitmanually.Instead,Ilet
Server.CreateObject()doallthework.<BR>
<STRONG>
<%
Server.ScriptTimeout=10
varASPScriptObject=Server.CreateObject("Scripting.FileSystemObject");
varmyPath=Server.MapPath("\\")+"\\Section04\\script14a.asp"
varAspScript=ASPScriptObject.OpenTextFile(myPath);
varoutputScript="";

while(!AspScript.AtEndOfStream)
	{
	outputScript+=AspScript.ReadLine()+"\r";
	}

outputScript=newString(outputScript);
outputScript=Server.HTMLEncode(outputScript)
AspScript.Close();
outputScript="<PRE>"+outputScript+"</PRE>";
Response.Write(outputScript)
%>
</STRONG>
</BODY>
</HTML>

ClickHeretorunthescriptinanewwindow.

Idemonstratedfourmethodsinthescript14.asp.We"lltakethemfromtoptobottom.

ExplainingtheScript:

Server.URLEncode()doesexactlywhatyouthinkitdoes.IttakesastringandencodesittoRFC1738standards.That"smorethanyoueverwantedtoknowaboutServer.URLEncode(),isn"tit?

NextwehaveServer.CreateObject().InthiscaseIcreatedaninstanceoftheFileSystemObject.ThemostcommonobjectsthatyouwillinstanciateareADODB.Recordset,Scripting.FileSystemObject,Scripting.Dictionary,MSWC.AdRotator,MSWC.BrowserType,MSWC.NextLink,andMSWC.ContentRotator.TherearemanygoodresourcesonallofthesecreatedObjects.Mostofthemarebeyondthescopeofthiswebsite.

NextonthelistisServer.MapPath().Lookingbackatscript14.asp,doyouseethedoubleslashes(\\)intheMapPathargument?That"snotanaccident.WehavetouseescapecharactersinJavaScript.

ThelastMethodIdemonstrateisServer.HTMLEncode().ItconvertsHTMLflagsintonon-HTMLequivalents.

TheLoneProperty:

Serverhasoneproperty:ScriptTimeout.Itsetsthemaximumnumberofsecondsallowableforscriptexecution.Ifthescriptexecutionexceedsthattime,thenittimesout.TheusergetsanuglymessagebutatleasttheWebServercanquitexecutingyourdarnedgreedyscriptandgoaboutotherbusiness.