当前位置:编程学习 > asp >>

asp入门教程:ASP Server 对象简单

asp入门教程:ASP Server 对象简单

在ASP服务器对象用于访问属性和方法在服务器上。

好了下面我们来看一个实例:

<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>

This file was last modified on: 01/10/2007 03:40:59

实例二.

<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 border="0" src="/images/btn_view_text.gif"></a>
</p>
输出结果.

Hello World line 1
Hello World line 2
Hello World line 3

实例三.

<%
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

%>
<html>
<body>
<p>
This page has been visited <%=fcount%>  times.
</p>
</body>
</html>
 输出结果.

This page has been visited 12345 times.

转载请注明来自http://www.226500.cn/asp/asp.html

补充:asp教程,ASP入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,