站长百科(www.zzbaike.com) 站长自己的百科全书
用ASP实现的网页和程序
出处:站长百科
原文地址:http://www.zzbaike.com/wiki/用ASP实现网页BBS
本电子书整理自站长百科用ASP实现网页BBS词条,查看最新内容请访问网站
HostEase拥有中文网站(http://cn.hostease.com)的美国主机商 中国访问最快的美国主机 中文网站轻
松 选 购 支 付 宝 付 款 购 买 快 捷 中 文 客 户 服 务 沟 通 更 方 便 , 轻 松 省 钱 请 看 优 惠 码
http://www.idcspy.com/top/hostease/
推荐内容: HostEase主机中文网站 | HostEase优惠码
用ASP实现网页BBS
传统的网页 BBS 大多是采用 CGI 模式实现的,它的实现要求编程者既要掌握编程语言如
Perl 或 C 等,又要了解关于 CGI 模式的各项技术内容,因此要制作自己的网页 BBS 确实困
难不小。ASP(Active Server Pages 动态服务器主页)的出现,使我们眼前一亮,能不能
利用 ASP 实现网页 BBS 呢?回答当然是肯定的。ASP 的诱人之处就在于它提供了一种简单易
学的脚本,并带有许多内置的对象,从而提供了一条简捷的编程之路。
该 BBS 主要由用户注册(浏览器端)、用户注册(服务器端)、加帖子(浏览器端)、加
帖子(服务器端)、帖子具体内容的显示和回复以及所有帖子的显示六个部分组成,其中用
户信息存放在数据库 author.mdb 中,帖子存放在数据库 bbs.mdb 中。它们均为 ACCESS 数据
库,结构分别如
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
1、表 2 所示。
表 1 author.mdb
字段名 数据类型 长度 说明
Authname 文本 24 用户名
Password 文本 10 密码
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
表 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>
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
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/images/backgrnd.gif">
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
<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:\inetpub\wwwroot\hosp\asp\data.id", 1,
False, False)
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
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 %>
站长百科(www.zzbaike.com) 站长自己的百科全书
</body>
</html>
5、帖子具体内容的显示和回复 detail.asp
<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>
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
<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/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>
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
-<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>
用ASP编写下载网页中所有资源的程序
看过一篇关于下载网页中图片的文章,它只能下载以 http 头的图片,我做了些改进,
可以下载网页中的所有连接资源,并按照网页中的目录结构建立本地目录,存放资源。
download.asp?url=你要下载的网页
download.asp 代码如下:
<%
Server.ScriptTimeout=9999
function SaveToFile(from,tofile)
on error resume next
dim geturl,objStream,imgs
geturl=trim(from)
Mybyval=getHTTPstr(geturl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type =1
objStream.Open
objstream.write Mybyval
objstream.SaveToFile tofile,2
objstream.Close()
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
set objstream=nothing
if err.number<>0 then err.Clear
end function
function geturlencodel(byval url)'中文文件名转换
Dim i,code
geturlencodel=""
if trim(Url)="" then exit function
for i=1 to len(Url)
code=Asc(mid(Url,i,1))
if code<0 Then code = code + 65536
If code>255 Then
geturlencodel=geturlencodel&"%"&Left(Hex(Code),2)&"%"&Right(Hex(Code),2)
else
geturlencodel=geturlencodel&mid(Url,i,1)
end if
next
end function
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
function getFileName(byval filename)
if instr(filename,"/")>0 then
fileExt_a=split(filename,"/")
getFileName=lcase(fileExt_a(ubound(fileExt_a)))
if instr(getFileName,"?")>0 then
getFileName=left(getFileName,instr(getFileName,"?")-1)
end if
else
getFileName=filename
end if
end function
function getHTTPstr(url)
on error resume next
dim http
set http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPstr=Http.responseBody
set http=nothing
if err.number<>0 then err.Clear
end function
Function CreateDIR(ByVal LocalPath) '建立目录的程序,如果有多级目录,则一级一级
的创建
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
On Error Resume Next
LocalPath = Replace(LocalPath, "\", "/")
Set FileObject = server.CreateObject("Scripting.FileSystemObject")
patharr = Split(LocalPath, "/")
path_level = UBound(patharr)
For I = 0 To path_level
If I = 0 Then pathtmp = patharr(0) & "/" Else pathtmp = pathtmp & patharr(I)
& "/"
cpath = Left(pathtmp, Len(pathtmp) - 1)
If Not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath
Next
Set FileObject = Nothing
If Err.Number <> 0 Then
CreateDIR = False
Err.Clear
Else
CreateDIR = True
End If
End Function
function GetfileExt(byval filename)
fileExt_a=split(filename,".")
GetfileExt=lcase(fileExt_a(ubound(fileExt_a)))
end function
function getvirtual(str,path,urlhead)
if left(str,7)="http://" then
url=str
elseif left(str,1)="/" then
start=instrRev(str,"/")
if start=1 then
url="/"
else
url=left(str,start)
end if
url=urlhead&url
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
elseif left(str,3)="../" then
str1=mid(str,inStrRev(str,"../")+2)
ar=split(str,"../")
lv=ubound(ar)+1
ar=split(path,"/")
url="/"
for i=1 to (ubound(ar)-lv)
url=url&ar(i)
next
url=url&str1
url=urlhead&url
else
url=urlhead&str
end if
getvirtual=url
end function
'示例代码
dim dlpath
virtual="/downweb/"
truepath=server.MapPath(virtual)
if request("url")<> "" then
url=request("url")
fn=getFileName(url)
urlhead=left(url,(instr(replace(url,"//",""),"/")+1))
urlpath=replace(left(url,instrRev(url,"/")),urlhead,"")
strContent = getHTTPPage(url)
mystr=strContent
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "(src|href)=.[^\>]+? "
Set Matches =objRegExp.Execute(strContent)
For Each Match in Matches
str=Match.Value
str=replace(str,"src=","")
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
str=replace(str,"href=","")
str=replace(str,"""","")
str=replace(str,"'","")
filename=GetfileName(str)
getRet=getVirtual(str,urlpath,urlhead)
temp=Replace(getRet,"//","**")
start=instr(temp,"/")
endt=instrRev(temp,"/")-start+1
if start>0 then
repl=virtual&mid(temp,start)&" "
'response.Write repl&"<br>"
mystr=Replace(mystr,str,repl)
dir=mid(temp,start,endt)
temp=truepath&Replace(dir,"/","\")
CreateDir(temp)
'response.Write getRet&"||"&temp&filename&"<br><br>"
SaveToFile getRet,temp&filename
end if
Next
set Matches=nothing
end if
%>
站长百科(www.zzbaike.com) 站长自己的百科全书
出处:站长百科
原文地址:http://www.zzbaike.com/wiki /用 ASP 实现网页 BBS
本电子书整理自站长百科用 ASP 实现网页 BBS 词条,查看最新内容请访问网站
更多电子书
freehost4life美国免费空间 (http://www.freehost4life.com), 服务器位于
softlayer的达拉斯机房,是中国访问速度最快的美国主机之一。
wordpress的中文翻译文档http://www.wordpress.la/codex.html,wordpress
开发的相关知识都有,对WordPress开发感兴趣的博主会有一定的用处。
WordPress免费主题:http://www.wordpress.la/theme.html
WordPress免费插件:http://www.wordpress.la/plugin.html
WordPress主题制作电子书:http://bbs.zzbaike.com/thread-9954-1-1.html
Apache2.2 中文文档电子书http://bbs.zzbaike.com/thread-9955-1-1.html
IXWeHosting 控制面板使用手册(在线版+PDF 电子书)
http://bbs.zzbaike.com/thread-9953-1-1.html
更多电子书下载:http://down.zzbaike.com/ebook/
视频教程:
1. 美国主机 IXWebHosting 使用视频教程(在线观看及下载)
http://bbs.zzbaike.com/thread-47008-1-1.html
2. Godaddy 主机及域名使用视频教程(在线观看及下载)
http://bbs.zzbaike.com/thread-50005-1-1.html
如果您有站长类电子书,请到这里与我们分享:
http://bbs.zzbaike.com/forum-69-1.html
详情见: http://bbs.zzbaike.com/thread-23156-1-1.html
站长百科感谢您下载阅读,多谢支持!
用ASP实现的网页和程序
用ASP实现网页BBS
用ASP编写下载网页中所有资源的程序
附录