目录搜索
文字
分享

ASP Server 对象



Server 对象用于访问有关服务器的属性和方法。


Server 对象

ASP Server 对象用于访问有关服务器的属性和方法。其属性和方法描述如下:

属性

属性 描述
ScriptTimeout 设置或返回在一段脚本终止前它所能运行时间(秒)的最大值。

方法

方法 描述
CreateObject 创建对象的实例。
Execute 从另一个 ASP 文件中执行一个 ASP 文件。
GetLastError() 返回可描述已发生错误状态的 ASPError 对象。
HTMLEncode 把 HTML 编码应用到某个指定的字符串。
MapPath 把一个指定的路径映射到一个物理路径。
Transfer 把一个 ASP 文件中创建的所有信息发送(传输)到另一个 ASP 文件。
URLEncode 把 URL 编码规则应用到指定的字符串。

在线实例

此文件最后被修改的时间是?
探测文件的最后修改时间。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<!DOCTYPE html>

<html>

<body>

 

<%

Set fs = Server.CreateObject("Scripting.FileSystemObject")

Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp"))

modified = rs.DateLastModified

%>

This file was last modified on: <%response.write(modified)

Set rs = Nothing

Set fs = Nothing

%>

 

</body>

</html>

打开并读取某个文本文件
打开文件 "Textfile.txt" 以供读取。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<!DOCTYPE html>

<html>

<body>

 

<%

Set FS = Server.CreateObject("Scripting.FileSystemObject")

Set RS = FS.OpenTextFile(Server.MapPath("text") & "\TextFile.txt",1)

While not rs.AtEndOfStream

      Response.Write RS.ReadLine

      Response.Write("<br>")

Wend 

%>

 

<p>

<a href="text/textfile.txt"><img src="/images/btn_view_text.gif"></a>

</p>

 

</body>

</html>

自制的点击计数器

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

<%

Set FS=Server.CreateObject("Scripting.FileSystemObject")

Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 1, False)

fcount=RS.ReadLine

RS.Close

 

fcount=fcount+1

 

'This code is disabled due to the write access security on our server:

'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False)

'RS.Write fcount

'RS.Close

 

Set RS=Nothing

Set FS=Nothing

 

%>

<!DOCTYPE html>

<html>

<body>

<p>

This page has been visited <%=fcount%>  times.

</p>

</body>

</html>