
<!--#include file=
"conn.asp"--><%
'连接数据库%>

<%
'On Error Resume Next '容错处理 如果你要是修改的话, 就先将这段注释了吧
Dim City
'定义一个city变量
'City=Request.Querystring("City") '获取一个city值

City=
"china" ' 这里我将这个city值赋了一个值 china
'HtmlStartName=Request.Querystring("HtmlStartName")'获得生成htm文件名前缀

HtmlStartName=
"index" '这个值原文是从request来的. 我这里做测试所以就改为了常量
Dim sql
'搜索字符串,这里我就直接打开表不用搜索变量了,搜索条件按自己写就可以
'sql="select * from Hotel where [City] = '" & City & "' " 这个也是原文的

sql=
"select id,title,pdate from tab1 order by id desc" '这是我自己定义的一个查询语句
Dim rs
'数据操作对象
Dim PageCounts
'实现分页生成必须得知呀有多少页
Set rs = Server.CreateObject(
"ADODB.Recordset")

rs.Open Sql,conn,1,1
'找开酒店等于City变量的表

rs.pagesize=10
'十个记录为一页

PageCounts=rs.pagecount
'得出要生成多少个页面,循环生成使用
Dim fs
'定义fso文件对象
Dim folders
'存放生成静态页的文件夹名称
Dim Filestart
'定义生成htm文件前缀
Set fs=Server.CreateObject(
"Scripting.FileSystemObject")
Dim i
for i=1
to PageCounts
'开始循环生成页面,也就是分页生成了

page=i

folders=server.mappath(
"CityHtml")
if (fs.FolderExists(folders))
Then '判断文件夹是否存在
else

fs.CreateFolder(folders)
'不存在则创建CityHtml文件夹
end if
if i=1
then

Filestart=HtmlStartName
'如果为第一页则定义文件名为传值名.例如beijing则为beijing.htm
else

Filestart=HtmlStartName&i
'如果第二页则为beijing+1例如有两页也就是i等于2则为 beijing2.htm如此类推...(.htm后缀就在后面加上)
end if
Dim files
'定义生成文本文件名称变量
Dim filez
'定义文件路径名称变量

files=Filestart&
".htm" '本文件名称

filez=folders&"\"&files
'文本文件路径
'删除文件
Dim checkfile
'检查文本文件是否已经存在,是则删除

checkfile=server.mappath(
"CityHtml\"&Filestart&".htm")
'检查htm文件是否已经存在,是则删除
if (fs.FileExists(checkfile))
Then '检查htm文件是否已经存在,是则删除
Dim df
'定义文件对象*删除文件使用*
Set df=fs.GetFile(checkfile)
'定义要删除的文件

df.delete
'删除文件
end If '判断结束
Dim ts
'定义写入文件对象
set ts = fs.createtextfile(filez,
true)
'开启写入文件内容**我在正文只简单写入酒店名称和静态数字分页显示

ts.write(
"<Html><Head><Title>生成静态"&City&
"标题</Title>"&vbcrlf)
'之后就是要生成的正文件内容了跟使用

ts.write(
"<META http-equiv=Content-Type content=text/html; charset=gb2312>"&vbcrlf)

ts.write(
"<meta name=keywords content="&city&
"酒店>"&vbcrlf)

ts.write(
"<link href='/Style/style.css' rel='stylesheet' type='text/css'></head><body topmargin=0>"&vbcrlf)

ts.Write(
"<TABLE WIDTH=760 cellspacing=0 cellpadding=0 align=center>"&vbcrlf&_
"<TR><TD width='100%'>"&vbcrlf)
'分页输出列表开始, 这部分你可以写成你的静态页

ts.write(
"<table border=0 width=80% style='margin-top:0px;margin-left:100px'>")

db=
"tab1"

head=
"<b>新闻标题</b>"
if rs.eof
and rs.bof
then

ts.write(
"<div align=center>暂无更多新闻发布!</div>"&vbcrlf)
else

ts.write(
"<tr><td>"& head &
"</td><td><b>发布时间</b></td></tr>"&vbcrlf)

ts.write(
"<tr><td height='10px;'></td></tr>"&vbcrlf)

rs.pagesize=rs.pagesize
'每页显示的条数

rs.absolutepage=i
For ii=1
To rs.pagesize
if rs.eof
then exit for

ntitle=
left(rs(
"title"),40)

ntime=DateValue(rs(
"pdate"))
if len(ntitle)<>
len(rs(
"title"))
then

ntitle=ntitle&
"..."
end if

str=
"<tr><td><font color='#191970'>[新闻]</font> <a href='newsact.asp?id="&rs("id")&"&action=news'>"&ntitle&"</a></td>"&_
"<td>"&Year(rs(
"pdate"))&
"-"&month(rs(
"pdate"))&
"-"&day(rs(
"pdate"))&
"</td><td></tr>"&vbcrlf

ts.write(str)

rs.movenext
next
' rs.close
' set rs=nothing

ts.write(
"</TD></tr>")&vbcrlf
end if

ts.write(
"</table>")&vbcrlf
'分页输出列表结束
'数字分页程序原理在这我就不多说了,不懂的朋友可在网上搜索一下
Dim page
'当前页
Dim Page2
'数字分页变量
Dim s
'数字分页变量
if page=1
then

ts.write (
" [首 页] [前一页] ")
else

ts.write (
" <a href="&HtmlStartName&
".htm"&
" class=blue>[首 页]</a> <a href="&HtmlStartName&
Replace(page-1,1,
"")&".htm
"&" class=blue>前一页</a> ")
end if

page2=(page-(page
mod 10))/10
if page2<1
then page2=0
for s=page2*10-1
to page2*10+10
if s>0
then
if s=
cint(page)
then

ts.write (
" <font color='#000000'>["& s & "]</font>")
else
if s=1
then

ts.write (
" <a href="&HtmlStartName&
replace(s,1,
"")&".htm
"&" class=blue>[
"& s &"]</a>")
else

ts.write (
" <a href="&HtmlStartName&s&
".htm"&
" class=blue>["& s &
"]</a>")
end if
end if
if s=rs.pagecount
then
exit for
end if
end if
next
if cint(page)=rs.pagecount
then

ts.write (
" [后一页] [尾 页]")
else

ts.write (
" <a href="&HtmlStartName&page+1&
".htm"&
" class=blue>[后一页]</a> <a href="&HtmlStartName&rs.pagecount&
".htm"&
" class=blue>[尾 页]</a>")
end if

ts.write(
"</TD></TR>")
'分页输出结束

ts.write(
"</Table></body></html>"&vbcrlf)

ts.close
set ts=
nothing '释放对象
Next
'循环生成结束(分页生成)
set EditFile=
nothing '释放对象
set fs=
Nothing '释放对象
'if err.number<>0 then '处理生成错误
'Response.write(City&"更新时发生未知错误<A href=ToHtml.asp?City="&City&"&HtmlName="&HtmlStartName&">重新更新</A>")
'else
'Response.Write(City&"更新已完成 "&Now())
'end if

%>
共有 0 条评论