盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

第3种途径---基于XML的ASP留言板

时间:2024/11/19作者:未知来源:盾怪网教程人气:

[摘要]</td> </tr> </table> <br> <% msgNum = msgNum-1 ''''倒序显示,...
</td>
</tr>
</table>
<br>
<%
msgNum = msgNum-1 ''''倒序显示,所以下一条留言的下标应是当前下标-1
next ''''循环。
%>
</center>
</body>
</html>

-------------------------------------------------------------------------
◆ 4 ◆ certain.asp 该文件用于向XML文件中添加记录,并确认留言。
-------------------------------------------------------------------------
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;

charset=gb2312">
<title>【殷亮的留言本】留言确认</title>
</head>
<script language=vbscript>
sub btn1_onclick '''''当按下"查看留言"时,将网页导至留言页面
window.location="guest.asp"
end sub

sub btn2_onclick
window.close
end sub
</script>

<body>

<% '定义一个函数,用于检取留言内容。
function htmlencode(str)
dim result
dim l
if isNULL(str) then
htmlencode=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"&lt"
case ">"
result=result+"&gt"
case else
result=result+mid(str,i,1)
end select
next
htmlencode=result
end function

set guestXml = Server.CreateObject("MSXML.DOMDocument")
guestXml.load(Server.MapPath("guest.xml"))
set root = guestXml.documentelement

name = Request.Form("textname") '''''检取表单的各项提交。
pic = Request.Form("list")
add = Request.Form("textadd")
email = Request.Form("textmail")
thistime = now()
msg = Request.Form("textmsg")

set newTag = guestXml.createelement("留言")
root.appendchild newTag

set currentTag = root.lastChild

set nameTag = guestXml.createelement("姓名")
nameTag.text=htmlencode(name)
currentTag.appendchild nameTag

set picTag = guestXml.createelement("头像")
picTag.text=pic
currentTag.appendchild picTag

set addTag = guestXml.createelement("来自")
addTag.text=htmlencode(add)
currentTag.appendchild addTag

set timeTag = guestXml.createelement("时间")
timeTag.text=thistime
currentTag.appendchild timeTag

set emailTag = guestXml.createelement("信箱")
emailTag.text=htmlencode(email)
currentTag.appendchild emailTag

set msgTag = guestXml.createelement("内容")
msgTag.text=htmlencode(msg)
currentTag.appendchild msgTag

guestXml.save(Server.MapPath("guest.xml"))
%>
<embed width="350" height="200" src="http://www.okasp.com/techinfo/pic/certain.swf" style="position: absolute; left: 214; top: 86">'''''一个FLASH文件。
<input type="button" value="查看留言" name="btn1"
style="position: absolute; left: 282; top: 313; border-style: solid; border-width: 1; background-color: #ABB52F">
<input type="button" value="关闭此页" name="btn2"
style="position: absolute; left: 414; top: 313; border-style: solid; border-width: 1; background-color: #ABB52F">
</body>
</html>

---------------------------------------------------------------------------------
备注:

由于我们是用XML文件保存数据,所以在添加数据时的HTML过滤是很重要的。在基于数据库的
留言本中不小心留下一个HTML标签也许不会造成什么太大的问题,但在XML中,后果是严重的
随便的一个标记,甚至随便的一个"<"都可以让你的留言本瘫痪。
如“<姓名>约翰<列浓</姓名>”………………………

上面四个文件源代码都已经过测试,复制后便可使用。
如果你想看示例演示,可以点击后面的链接 示例

你也可以从/article/UploadPic/2006-1/200617201115914.rar处
下载所有脚本文件与图像文件的压缩包。

旨在探讨,如有错漏,欢迎指正与讨论。

感谢站长miles这些日子来不倦的帮助,无以回报,唯有灌上此文。

关键词:第3种途径---基于XML的ASP留言板




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版