ASP的Server对象一共有7个方法(CreateObject Execute GetLastError URLEncode HTMLEncode MapPath Transfer),一个属性(ScriptTimeout),没有事件和集合。
CreatObject--Server.CreateObject("") 创建一个对象实例
Execute--Server.Execute("xxx.asp")执行一个外部文件,作用跟SSI相似
GetLastError--Server.GetLastError() 返回最后一个asp错误的位置和描述
URLEncode--Server.URLEncode("someString") 将string编码为URL标准
HTMLEncode--Server.HTMLEncode("someString") 将string编码为html字符
MapPath--Server.MapPath(//virtualDirectory) 将虚拟目录转换为物理目录
Transfer--Server.Transfer("xxx.asp") 将一个文件的执行结果传入另一个文件
ScriptTimeout--设定了一个script的执行时间(以秒为单位),如果超过此时间将超时。用户会得到一个提示,但是server会跳过此script继续做别的事情。
例子
<%@ language=javascript %>
<html>
<body>
<% =Server.URLEncode("hello, this is a URLEncoded string!")%><br><br>
<strong>the below is an example of CreatObject</strong><br>
<%
Server.ScriptTimeout=10;
var ASPServerObject=Server.CreateObject("Scripting.FileSystemObject");
var thePath=Server.MapPath("//")+"//asp//test17.asp";
var ASPScript=ASPServerObject.OpenTextFile(thePath);
var outputScript="";
while(!ASPScript.AtEndOfStream){
outputScript+=ASPScript.ReadLine()+"/r";
}
outputScript=new String(outputScript);
outputScript=Server.HTMLEncode(outputScript);
ASPScript.Close();
outputScript="<PRE>"+outputScript+"</PRE>";
Response.Write(outputScript);
%>
</body>
</html>
CreateObject可以有n多的对象实例,最常用的是ADODB.Recordset, Scripting.FileSystemObject, Scripting.Dictionary, MSWC.AdRotator, MSWC.BrowserType, MSWC.NextLink, and MSWC.ContentRotator等。