金属百叶窗计量:简单bbs
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 12:59:15
传统的网页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:由用户输入相关信息,通过表单传送到服
务器。
4、加帖子(服务器端)bbs.asp:接收帖子内容,并存入bbs.mdb中。
<%name=REQUEST.FORM("name")
code=REQUEST.FORM("code")
subject=REQUEST.FORM("subject")
content=REQUEST.FORM("content")
curdate=Date
curtime=Time
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
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
IfRequest.QueryString("ID")="" Then
manswernum=number
Else
manswernum=Request.QueryString("ID")
End If
IfRequest.QueryString("topnum")="" Then
mtopnum=number
Else
mtopnum=Request.QueryString("topnum")
End If
Set OutStream = Nothing
Set Connbbs =Server.CreateObject("ADODB.Connection")
Connbbs.Open "bbs"
Connbbs.Execute("INSERT INTObbs(ID,authname,subject,content,adddate,addtime,answernum,topnum,visitnum)Values('" &number& "','"
&name& "','"&subject& "','" &content& "','"&curdate& "','" &curtime& "','"&manswernum& "','" &mtopnum& "',0)")
Connbbs.Close %>
<% =curdate & " "%><% =curtime & " 添加贴子 " %>
姓名:<% =name%>
主题:<%=subject %>
内容:<%=content %>
<% Else %>
您的用户名或密码出错,请您重输!
<% End If
RS.Close
Connection.Close %>
5、帖子具体内容的显示和回复 detail.asp
<%idnum=Request.QueryString("ID")
SetConnection=Server.CreateObject("ADODB.Connection")
Connection.Open "bbs"
Set RS=Connection.Execute("SELECT *FROM bbs WHERE ID='" &idnum& "'") %>
姓名:<%=RS(1) %>
主题:<%=RS(2) %>
内容:<%=RS(3) %>
<% resub="Re:" &RS(2)
mtopnum=RS(8)
RS.Close
Connection.Close %>
6、所有帖子的显示 Dispbbs.asp:列出所有的帖子的主题、作者、时间、访问人数等信息。
<% SetConnection=Server.CreateObject("ADODB.Connection")
Connection.Open "bbs"
Set RS=Connection.Execute("SELECT *FROM bbs WHERE ID=answernum ORDER BY ID DESC")
Conn.Open "bbs"
Set RSNEXT=Conn.Execute("SELECT * FROMbbs")
Do While not RS.EOF %>
<% =RS(0) %>
=RS(4) &" " %><% =RS(7)%>(<% =RS(5) %>)
<% 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) %>
- <% RSNEXT.MoveNext RS.MoveNext RSNEXT.Close Conn.Close RS.Close Connection.Close %> 上述程序在Win NT4.0和IIS3.0上实现通过。 日期 科目 时间 地点 7月7日 网络工程 8:30—10:30 4-213 7月7日 Linux 15:00—17:00 4-212 7月11日 网络安全 8:30—10:30 4-212 7月14 微机原理 8:30—10:30 4-202