传统的网页bbs大多是采用cgi模式实现的,它的实现要求编程者既要掌握编程语言如perl或c等,又要了解关于cgi模式的各项技术内容,因此要制作自己的网页bbs确实困难不小。asp(active server pages 动态服务器主页)的出现,使我们眼前一亮,能不能利用asp实现网页bbs呢?回答当然是肯定的。asp的诱人之处就在于它提供了一种简单易学的脚本,并带有许多内置的对象,从而提供了一条简捷的编程之路。 
该bbs主要由用户注册(浏览器端)、用户注册(服务器端)、加帖子(浏览器端)、加帖子(服务器端)、帖子具体内容的显示和回复以及所有帖子的显示六个部分组成,其中用户信息存放在数据库author.mdb中,帖子存放在数据库bbs.mdb中。它们均为access数据库,结构分别如表1、表2所示。
表1 author.mdb
| 字段名 数据类型 长度 说明 authname 文本 24 用户名
 password 文本 10 密码
 | 
表2 bbs.mdb
| 字段名  数据类型  长度  说明 id 文本   4  帖子的编号
 authname  文本  24  用户名
 subject 文本 80 主题
 content 备注   内容
 adddate 日期/时间 加贴的日期
 visitnum  数字  长整型  访问人数
 answernum  文本 4 所回复帖子的编号
 (缺省为本身的编号)
 addtime  日期/时间 加贴的时间
 topnum 文本  4 第一层回复帖子的编号
 | 
具体实现方法如下所示,其中asp文件和数据库存放在“/hosp/asp"中,其它htm
文件存放在“/hosp"文件中,img文件存放在“/hosp/images"。
1、 用户注册(浏览器端)login.htm:由用户输入相关信息,通过表单传送到服
务器。
| <html> <head><title> register a new user</title><head>
 <body>
 <form method="post" action="/hosp/asp/register.asp"><p>
 <h2>为了标识方便,请您注册一个用户名称</h2>
 用户:<input type="text" name="name" size="24"><p>
 密码:<input type="password" name="password" size="24"><p>
 <input type=submit value="注 册">
 <input type=reset value="清 除">
 <a href="/hosp/asp/dispbbs.asp">返回论坛</a><p>
 </body>
 </html>
 | 
2、 用户注册(服务器端)register.asp:利用request.form("表单栏位名")接收表单信息,采用ado技术与数据库author.mdb连接,并将表单信息存入author.mdb中。
| <html> <head><title> 存用户信息 </title></head>
 <body>
 <!-- 取客户浏览器输入的用户名和密码 -->
 <% name=request.form("name")
 code=request.form("password")
 <!-- 与author.mdb连接 -->
 set connection=server.createobject("adodb.connection")
 connection.open "author"
 set rs=connection.execute("select * from author")
 <!-- 如果该用户名已存在,请重输,否则存入数据库 -->
 if not rs.eof then %>
 该用户名已被注册,请您重新<a href="/hosp/login.htm">注册</a>新用户名!
 <% else
 connection.execute("insert into author(authname,password) values('" &name& "','" &code& "')")
 rs.close
 connection.close %>
 <center><b><% =name %></b> 您已注册成功!<p>
 <a href="/hosp/asp/dispbbs.asp">返回论坛</a></center>
 <% end if %>
 </body>
 </html>
 | 
 
3、 加帖子(浏览器端)bbs_add.htm:由用户输入待加入帖子的相关信息,并传到服务器。
| <html> <head><title> a sample form </title></head>
 <body background="/hosp/backgrnd.gif">
 <form method="post" action="/hosp/asp/bbs.asp"><p>
 姓名: <input name="name" size="28"> 密码: <input type="password" name="code" size="28"><p>
 主题:<input name="subject" size="66"><p>
 内容:<p>
 <textarea name="content" rows=20 cols=72></textarea><p>
 <center><input type=submit value="发布信息">
 <input type=reset value="清除信息"></center>
 </form>
 </body>
 </html>
 | 
4、 加帖子(服务器端)bbs.asp:接收帖子内容,并存入bbs.mdb中。
| <html> <head><title>bbs.asp</title></head>
 <body>
 <% name=request.form("name")
 code=request.form("code")
 subject=request.form("subject")
 content=request.form("content")
 curdate=date
 curtime=time
 <!-- 与author.mdb连接 -->
 set connection = server.createobject("adodb.connection")
 connection.open "author"
 set rs = connection.execute("select * from author where authname='" &name& "' and password='" &code& "'")
 <!-- 判断用户名与密码是否匹配 -->
 if not rs.eof then
 <!-- 打开数据文件,该文件存放帖子的编号,每加一个帖子,编号加1 -->
 set fileobject = server.createobject("scripting.filesystemobject")
 set instream = fileobject.opentextfile ("c:inetpubwwwroothospaspdata.id", 1, false, false)
 number = cstr(instream.readline+1)
 set outstream = fileobject.createtextfile ("c:inetpubwwwroothospaspdata.id", true, false)
 outstream.writeline number
 if request.querystring("id")="" then
 manswernum=number
 else
 manswernum=request.querystring("id")
 end if
 if request.querystring("topnum")="" then
 mtopnum=number
 else
 mtopnum=request.querystring("topnum")
 end if
 set outstream = nothing
 <!-- 与bbs.mdb连接,将帖子信息存入数据库中 -->
 set connbbs = server.createobject("adodb.connection")
 connbbs.open "bbs"
 connbbs.execute("insert into bbs(id,authname,subject,content,adddate,addtime,answernum,topnum,visitnum) values('" &number& "','"
 &name& "','" &subject& "','" &content& "','" &curdate& "','" &curtime& "','" &manswernum& "','" &mtopnum& "',0)")
 connbbs.close %>
 <% =curdate & " " %><% =curtime & " 添加贴子 " %>
 <a href="http://nt-server/hosp/asp/dispbbs.asp">返回论坛</a><p>
 姓名:<% =name %><p>
 主题:<% =subject %><p>
 内容:<% =content %><p>
 <% else %>
 您的用户名或密码出错,请您重输!
 <% end if
 rs.close
 connection.close %>
 </body>
 </html>
 
 | 
5、帖子具体内容的显示和回复 detail.asp 
| <html> <head><title>bbs.asp</title></head>
 <body background="/hosp/backgrnd.gif">
 <% idnum=request.querystring("id")
 set connection=server.createobject("adodb.connection")
 connection.open "bbs"
 set rs=connection.execute("select * from bbs where id='" &idnum& "'") %>
 姓名:<% =rs(1) %><p>
 主题:<% =rs(2) %><p>
 内容:<% =rs(3) %><p>
 
 ------------------------------------------------------------------------------
 <! --形成回复表单 -->
 <% resub="re:" & rs(2)
 mtopnum=rs(8)
 rs.close
 connection.close %>
 <form method="post" action="/hosp/asp/bbs.asp?id=<% =idnum %>&topnum=<% =mtopnum %>"><p>
 姓名: <input name="name" size="28"> 密码: <input type="password" name="code" size="28"><p>
 主题:<input name="subject" size="66" value="<% =resub %>"><p>
 内容:<p>
 <textarea name="content" rows=20 cols=72></textarea><p>
 <center><input type=submit value="信息回复">
 <input type=reset value="清除信息"></center>
 </form>
 <a href="http://nt-server/hosp/asp/dispbbs.asp">返回论坛</a>
 </body>
 </html>
 
 | 
6、所有帖子的显示 dispbbs.asp:列出所有的帖子的主题、作者、时间、访问人数等信息。
| 
 <html>
 <head><title>dispbbs.asp</title></head>
 <body background="/hosp/backgrnd.gif">
 <center><img src="http://edu.chinaz.com/hosp/luntan.gif" border=0></center><p>
 <center><a href="/hosp/login.htm"><img src="http://edu.chinaz.com/hosp/zhuce.gif" border=0></a>
 <a href="/hosp/bbs_add.htm"><img src="http://edu.chinaz.com/hosp/jiatz.gif" border=0></a>
 <a href="/hosp/default.htm"><img src="http://edu.chinaz.com/hosp/return.gif" border=0></a></center><p>
 <% set connection=server.createobject("adodb.connection")
 connection.open "bbs"
 set rs=connection.execute("select * from bbs where id=answernum order by id desc")
 set conn=server.createobject("adodb.connection")
 conn.open "bbs"
 set rsnext=conn.execute("select * from bbs")
 do while not rs.eof %>
 <% =rs(0) %> <a href="/hosp/asp/detail.asp?id=<% =rs(0) %>"><% =rs(2) %></a> -<font size="4"><b><% =rs(1) %></b></font> <%
 =rs(4) &" " %><% =rs(7) %>(<% =rs(5) %>)<p>
 <% set rsnext=conn.execute("select * from bbs where topnum<>id and opnum='" &rs(0)& "' order by id asc")
 do while not rsnext.eof %>
 <% =rsnext(0) %> <a href="/hosp/asp/detail.asp?id=<% =rsnext(0) %>">re<% rsnext(6) %>:<% =rsnext(2) %></a>
 -<font size="4"><b><% =rsnext(1) %></b></font> <% =rsnext(4) &" " %><% =rsnext(7) %>(<% =rsnext(5) %>)<p>
 <% rsnext.movenext
 loop
 rs.movenext
 loop
 rsnext.close
 conn.close
 rs.close
 connection.close %>
 </body>
 </html>
 | 
上述程序在win nt4.0和iis3.0上实现通过。