传统的网页BBS大多是采用CGI模式实现的,它的实现要求编程者既要掌握编程语言如Perl或C等,又要了解关于CGI模式的各项技术内容,因此要制作自己的网页BBS确实困难不小。ASP(Active Server Pages 动态服务器主页)的出现,使我们眼前一亮,能不能利用ASP实现网页BBS呢?回答当然是肯定的。ASP的诱人之处就在于它提供了一种简单易学的脚本,并带有许多内置的对象,从而提供了一条简捷的编程之路。
<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>
<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>
<html>
<head><title> a sample form </title></head>
<body background="/hosp/images/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>
<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:\inetpub\wwwroot\hosp\asp\data.id", 1, False, False)
number = Cstr(InStream.Readline+1)
Set OutStream = FileObject.CreateTextFile ("c:\inetpub\wwwroot\hosp\asp\data.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>
<html>
<head><title>bbs.asp</title></head>
<body background="/hosp/images/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>
<html>
<head><title>dispbbs.asp</title></head>
<body background="/hosp/images/backgrnd.gif">
<CENTER><IMG SRC="/hosp/images/luntan.gif" BORDER=0></CENTER><P>
<CENTER><A HREF="/hosp/login.htm"><IMG SRC="/hosp/images/zhuce.gif" BORDER=0></A>
<A HREF="/hosp/bbs_add.htm"><IMG SRC="/hosp/images/jiatz.gif" BORDER=0></A>
<A HREF="/hosp/default.htm"><IMG SRC="/hosp/images/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>