新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:Haneng.com的简单留言板制作源程序例子

Haneng.com的简单留言板制作源程序例子

新客网 XKER.COM 2003-04-16 来源: 收藏本文
default.asp
-------------------------------
<HTML><BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<B>This is my guestbook. Use this form to submit your greeting:</B><BR>

<FORM METHOD="POST" ACTION="write.asp">
<INPUT NAME="new_line" TYPE="TEXT" SIZE=35>
<INPUT TYPE="SUBMIT" VALUE="Add greeting">
</FORM>
<BR><BR>
<%
MyFile = "c:\guestbook.txt"

'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)

'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<HR>
<%=MyTextFile.ReadLine%>
</HR>
<%
WEND

'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>
<HR>
</BODY>
</HTML>

----------------------------




write.asp
----------------------------
<%
'Type in the path of the file to use. Make sure that the script has write access.
MyFile = "c:\guestbook.txt"

'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)

'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(New_line)

'Closes the file
MyOutStream.Close

'Sends them back to the default page
Response.Redirect "default.asp"
%>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐