急!!!请问哪里有自动生成静态页面的教程和程序例子??(就像新浪那样的做法)请指教!!

jamex 2000-05-31 10:21:00
急!!!请问网上哪里有学习如何自动生成静态页面的教程和程序例子下载??(就像新浪站点那样的做法)请指教!!谢谢!!
...全文
140 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hpboy 2000-06-02
  • 打赏
  • 举报
回复
csdn.net应该也是这样吧~使用一个“静态”的ASP页面来改进你的服务器的性能通常大家
显示一个数据库中的信息时都是使用动态页面来生成的,这对于一个小网站或者当数据库
内的容量不大时,系统的性能并没有什么影响。但是当用户要频繁地访问一个数据量很大
的库时,系统是不是还能够承受得了了。下面介绍一种“静态”ASP技术来解决这个问题。
例如现在这个有一个人员资料库,结构如下:
ID First Last Company Email Phone
常规的办法如下:
contact.asp
<table cellspacing=0 cellpadding=0>
<%
set query = getdb.execute("select * from contacts order by firstname, lastname")
do while not query.eof

response.write "<tr><td><a href="""
response.write "detail.asp?id=" & query("id")
response.write """>" & query("first") & " " & query("last")
response.write "</a></td></tr>"
query.movenext

loop
query.close
set query = nothing
%>
</table>

detail.asp
<table cellspacing=0 cellpadding=0>
<%
set query = getdb.e xecute("select * from contacts where id=" & request("id"))
if not query.eof then

response.write "<tr>"
response.write "<td>Name: </td><td>" & query("first") & " " & query("last") & "</td>"
response.write "<td>Company: </td><td>" & query("company") & "</td>"
response.write "<td>E-mail: </td><td>" & query("email") & "</td>"
response.write "<td>Phone: </td><td>" & query("phone") & "</td>"
response.write "</tr>"

query.movenext

end if
query.close
set query = nothing
%>
</table>

我想大家对上面的代码应该是不会有什么疑问的,显然它存在我上面提出的那个问题。
就是当每次显示一个人的详细资料时,都会读取数据库。
现在我提出的这个想法其实很简单,就是使用一个“静态”的ASP页面来代替读取数据库
的操作。
调用格式如下:
"Contact" & ID & ".asp"
例如我想读取id为27的人的信息,我就不用去查取数据库了,只要显示一个静态的
"Contact27.asp"就可以了。
这时你也许会说,如果我要改变了一个人的信息怎么办,其实只要在将
用户信息保存后的同时也改写这个静态页面,代码如下,有没有兴趣研究研究呀。
sub GenerateContactCacheFile(id)
dim query
set query = getdb.execute("select * from contacts where id=" & id)
if not query.eof then
dim filename
filename = "Contact" & id & ".asp"
dim fso
set fso = server.createobject("scripting.filesystemobject")
dim file
set file = fso.createtextfile(filename)
file.writeline "<html><head>"
file.writeline "<title>Contact: " & query("first") & " " & query("last") & "</title>"
file.writeline "</head><body>"
file.writeline "<table cellspacing=0 cellpadding=0>"
file.writeline "<tr>"
file.writeline "<td>Name: </td><td>" & query("first") & " " & query("last") & "</td>"
file.writeline "<td>Company: </td><td>" & query("company") & "</td>"
file.writeline "<td>E-mail: </td><td>" & query("email") & "</td>"
file.writeline "<td>Phone: </td><td>" & query("phone") & "</td>"
file.writeline "</tr>"
file.writeline "</table>"
file.writeline "</body></html>"
file.close
set file = nothing
end if
query.close
set query = nothing

end sub
使用模版,很多人在编程的时候都喜欢使用模版文件,我也很喜欢这样
因为这样能够让整个网站的风格保持一致,同时还可以免去讨厌的frame
一个典型的使用模版文件的代码如下:
<html>
<head>
<title>我的主页</title>
<!-- #include file="style.inc" -->
</head>
<body>
<!-- #include file="navstart.inc" -->
<!-- #include file="adbox.inc" -->

......这一页的内容.....

<!-- #include file="adbox.inc" -->
<!-- #include file="navend.inc" -->
</body>
</html>

这样,当你有多个“静态”页面时,尤其是上万个页面时,可以使用下面这种方式:
sub GenerateHeader(file, title)
file.writeline "<html><head>"
file.writeline "<title>" & title & "</title>"
file.writeline "<!-- #include file="style.inc" -->"
file.writeline "</head></body><body>"
file.writeline "<!-- #include file="navstart.inc" -->"
file.writeline "<!-- #include file="adbox.inc" -->"
end sub

sub GenerateFooter(file)
file.writeline "<!-- #include file="adbox.inc" -->"
file.writeline "<!-- #include file="navend.inc" -->"
file.writeline "</body></html>"
end sub


GenerateHeader file, "Contact: " & query("first") & " " & query("last")
file.writeline "<table cellspacing=0 cellpadding=0>"
file.writeline "<tr>"
file.writeline "<td>Name: </td><td>" & query("first") & " " & query("last") & "</td>"
file.writeline "<td>Company: </td><td>" & query("company") & "</td>"
file.writeline "<td>E-mail: </td><td>" & query("email") & "</td>"
file.writeline "<td>Phone: </td><td>" & query("phone") & "</td>"
file.writeline "</tr>"
file.writeline "</table>"
GenerateFooter file


最后是在contacts.asp中把从数据库中读数据改成读“静态页面”就可以了。
response.write "<tr><td><a href="""
response.write "contact" & query("id") & ".asp" ' point the link to the cache page...
response.write """>" & query("first") & " " & query("last")
response.write "</a></td></tr>"
试试把,这个方法能够把你服务器的性能大大提高的哦。呵呵~这样该满意了吧?
hpboy 2000-06-01
  • 打赏
  • 举报
回复
http://builder.chinabyte.com/builder_course.shtm?buiid=479&parid=1&cate=GJBC
hpboy 2000-06-01
  • 打赏
  • 举报
回复
http://builder.chinabyte.com/builder_course.shtm?buiid=429&parid=1&cate=GJBC
hcat1999 2000-06-01
  • 打赏
  • 举报
回复
没看到CSDN现在帖子也都是静态的页面吗?
用ASP对指定的文件操作就可以了
jamex 2000-05-31
  • 打赏
  • 举报
回复
to hpboy:
请问在builder.chinabyte.com 的那个页面中可找到,我找了好久也没找到有关内容,这个站点又没有搜索器可用!!还望多多帮忙!!!在此谢过!!!
hpboy 2000-05-31
  • 打赏
  • 举报
回复
builder.chinabyte.com有相关
的文档~~

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧