| < % |
Name = Request("Name") ) Email =
Request("Email") Subject = Request("Subject") Memo =
Request("Memo") |
| '从留言表单取得数据 |
If Name = "" Or Email = "" Or
Subject = "" Or Memo = "" Then Response.Write "输入框不能为空白!"
Response.End End If |
| '检查表单的各输入框是否有信息输入,若留有空输入框没填则显示说明信息:"输入框不能为空白!"
并停止执行下面的程序。? |
Line1 = "留言人:" & Name Line1 =
Line1 & String(5, " ") Email = "< A HREF=mailto:"
& Email & ">" & Email & "< /A>"
Line1 = Line1 & "Email" & Email & "<
BR>" Line2 = "主 题:" & Subject & "< BR>"
|
Memo = Replace( Memo, vbCrLf, "<
BR>" ) Line3 = "< TABLE BORDER=1>< TR><
TD>" Line3 = Line3 & "您的留言:" & Memo & "<
/TD>< /TR>< /TABLE>" Line4 = "时 间:" &
Now() |
| '定义留言的显示格式,其中留言信息用信息框框起来。 |
| On Error Resume Next |
| '避免如果执行下面的ReadAll(读取已打开文件的全部信息)时,无法读取信息就造成的程序错误的情况发生,因此加入此句用于忽略所有的错误。 |
Set fso =
Server.CreateObject("Scripting.FileSystemObject")
Application.Lock TxtPath = Server.MapPath("book1.txt")
NewPath = Server.MapPath("newbook.txt") fso.MoveFile
TxtPath, NewPath Set fin = fso.OpenTextFile(NewPath, ,
True) Set fout = fso.CreateTextFile(TxtPath) |
| '建立
FileSystemObject对象,并锁定Application对象,不让任何两位上网者同时执行留言操作,同时建立和打开一个TextStream对象,指向要对其实行僮鳎糜诹粞约锹嫉奈谋綽ook1.txt。 |
fout.WriteLine Line1 fout.WriteLine
Line2 fout.WriteLine Line3 fout.WriteLine Line4
fout.WriteLine "< hr>" fout.WriteLine
fin.ReadAll |
| '把留言表单中的信息分行写入到已打开的文件中。 |
fin.Close fso.DeleteFile NewPath, True
Application.UnLock Response.Redirect "guestbook1.asp"
|
| '关闭并删除gbookold.txt,然后解除Application对象的锁定,再指引客户端浏览器到新的Web页面guestbook1.asp。 |
| %> |
| 将上述代码COPY到你的记事本,注意:要记得将所有“<”符号后面多加的空格去掉,然后存成文件manage1.asp。
|