因为公司要开发一个新闻系统,要用到生成静态页面,生成的同时并对静态页面内容分页。用了不到半天的时间搞定了,目前只能实现上下页,没有页码跳转(形如123……)。但对这段代码继续完善一下就能达到页码分页的效果。
<%'接受传递值
Title=request.form("Title")
BidMeetingTime=request.form("BidMeetingTime")''''''''''''''展会时间
BidMeetingLocation=request.form("BidMeetingLocation")''''''''''''展会地点
'response.write title
'response.end()
Author=request.form("Author")
Keyword_1=request.form("Keyword_1")
Keyword_2=request.form("Keyword_2")
Keyword_3=request.form("Keyword_3")
Keyword_4=request.form("Keyword_4")
Keyword_5=request.form("Keyword_5")
Froms=request.form("Froms")
CreateTime=request.form("CreateTime")
ViewTimes=request.form("ViewTimes")
FirstClass=request.form("FirstClass")
SecondClass=request.form("SecondClass")
ThirdClass=request.form("ThirdClass")
'response.write SecondClass
'response.End()
'ThirdClass=request.form("ThirdClass")
Content1=request.form("Content1")
IsCheckPass=request.form("IsCheckPass")
IsHotPoint=request.form("IsHotPoint")
IsRecommend=request.form("IsRecommend")

Title=request.form("Title")
BidMeetingTime=request.form("BidMeetingTime")''''''''''''''展会时间
BidMeetingLocation=request.form("BidMeetingLocation")''''''''''''展会地点
'response.write title
'response.end()
Author=request.form("Author")
Keyword_1=request.form("Keyword_1")
Keyword_2=request.form("Keyword_2")
Keyword_3=request.form("Keyword_3")
Keyword_4=request.form("Keyword_4")
Keyword_5=request.form("Keyword_5")
Froms=request.form("Froms")
CreateTime=request.form("CreateTime")
ViewTimes=request.form("ViewTimes")
FirstClass=request.form("FirstClass")
SecondClass=request.form("SecondClass")
ThirdClass=request.form("ThirdClass")
'response.write SecondClass
'response.End()
'ThirdClass=request.form("ThirdClass")
Content1=request.form("Content1")
IsCheckPass=request.form("IsCheckPass")
IsHotPoint=request.form("IsHotPoint")
IsRecommend=request.form("IsRecommend")
%>
<
%
'
生成HTML文件名,建立文件夹,指定文件路径
fname
=
makefilename(now())
'
makefilename为自定义函数
StaticFilePath
=
date
()
&
"
/
"
&
fname
&
"
.shtml
"
'
存储在数据库中的路径
folder
=
"
../../allfiles/NewsInfo/newsfile/
"
&
date
()
&
"
/
"
filepath
=
folder
&
fname

%
>

<
%
'
将接受值及路径保持至数据库表
sql
=
"
insert into inNews(Title,Author,Keyword_1,Keyword_2,Keyword_3,Keyword_4,Keyword_5,Froms,FirstClass,SecondClass,ThirdClass,Content1,IsCheckPass,IsHotPoint,IsRecommend,StaticFilePath,BidMeetingTime,BidMeetingLocation) values('
"
&
Title
&
"
','
"
&
Author
&
"
','
"
&
Keyword_1
&
"
','
"
&
Keyword_2
&
"
','
"
&
Keyword_3
&
"
','
"
&
Keyword_4
&
"
','
"
&
Keyword_5
&
"
','
"
&
Froms
&
"
','
"
&
FirstClass
&
"
','
"
&
SecondClass
&
"
','
"
&
ThirdClass
&
"
','
"
&
Content1
&
"
','
"
&
IsCheckPass
&
"
','
"
&
IsHotPoint
&
"
','
"
&
IsRecommend
&
"
','
"
&
StaticFilePath
&
"
','
"
&
BidMeetingTime
&
"
','
"
&
BidMeetingLocation
&
"
')
"
'
response.write sql
'
response.end
Set
rsinsert
=
Server.CreateObject (
"
ADODB.Recordset
"
)
rsinsert.Open sql,conn,
1
,
3
Set
rsinsert
=
Nothing

%
>

<%
ContentStr=split(Content1,"|||")
PageNumber=ubound(ContentStr)
'response.write PageNumber
'response.end()
'if PageNumber=0 then
For p = 0 to ubound(ContentStr)
'打开模板代码,并将其中特殊代码转变为接受值
Dim fso,fin
'创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Model="../../allfiles/NewsInfo/news/Topic_civil_tec.shtml"


















<%
ContentStr=split(Content1,"|||")
PageNumber=ubound(ContentStr)
'response.write PageNumber
'response.end()
'if PageNumber=0 then
For p = 0 to ubound(ContentStr)
'打开模板代码,并将其中特殊代码转变为接受值
Dim fso,fin
'创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Model="../../allfiles/NewsInfo/news/Topic_civil_tec.shtml"
Set fin=fso.OpenTextFile(Server.MapPath(""&Model&""))
mb_code=fin.ReadAll
fin.close
mb_code=fin.ReadAll
fin.close
Title=htmlencode(Title)
Content=htmlencode(Content)
mb_code=replace(mb_code,"$Title",Title)
mb_code=replace(mb_code,"$Author",Author)
mb_code=replace(mb_code,"$Keyword_1",Keyword_1)
mb_code=replace(mb_code,"$Keyword_2",Keyword_2)
mb_code=replace(mb_code,"$Keyword_3",Keyword_3)
mb_code=replace(mb_code,"$Keyword_4",Keyword_4)
mb_code=replace(mb_code,"$Keyword_5",Keyword_5)
mb_code=replace(mb_code,"$Froms",Froms)
mb_code=replace(mb_code,"$CreateTime",formatdatetime(now(),2))
if ThirdClass<>"" then
mb_code=replace(mb_code,"$ThirdNewsClassId",ThirdClass)''''''替换模板中js中的特殊字符
end if
'mb_code=replace(mb_code,"$ViewTimes",ViewTimes)
mb_code=replace(mb_code,"$Content1",ContentStr(p))
Content=htmlencode(Content)
mb_code=replace(mb_code,"$Title",Title)
mb_code=replace(mb_code,"$Author",Author)
mb_code=replace(mb_code,"$Keyword_1",Keyword_1)
mb_code=replace(mb_code,"$Keyword_2",Keyword_2)
mb_code=replace(mb_code,"$Keyword_3",Keyword_3)
mb_code=replace(mb_code,"$Keyword_4",Keyword_4)
mb_code=replace(mb_code,"$Keyword_5",Keyword_5)
mb_code=replace(mb_code,"$Froms",Froms)
mb_code=replace(mb_code,"$CreateTime",formatdatetime(now(),2))
if ThirdClass<>"" then
mb_code=replace(mb_code,"$ThirdNewsClassId",ThirdClass)''''''替换模板中js中的特殊字符
end if
'mb_code=replace(mb_code,"$ViewTimes",ViewTimes)
mb_code=replace(mb_code,"$Content1",ContentStr(p))
if PageNumber>0 then
MyPagerTable="<table width=""60%"" border=""0"" cellpadding=""0"" cellspacing=""1""><tr><td height=""25""><a href=""$UrlUp""><font color=""ff0000""><strong>[上一页]</strong></font></a></td><td height=""30""><a href=""$UrlDown""><font color=""ff0000""><strong>[下一页]</strong></font></a></td></tr></table>"''''''''''下一页代码,用于替换
if p<=1 then''''''''''分页
MyPagerTable=replace(MyPagerTable,"$UrlUp",fname&".shtml")
if p=PageNumber then
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p&".shtml")
else
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p+1&".shtml")
end if
else
MyPagerTable=replace(MyPagerTable,"$UrlUp",fname&"_"&p-1&".shtml")
if p=PageNumber then
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p&".shtml")
else
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p+1&".shtml")
end if
end if
mb_code=replace(mb_code,"$MyPager",MyPagerTable)
else
mb_code=replace(mb_code,"$MyPager","")
end if
'mb_code=replace(mb_code,"$FirstClass",FirstClass)
'mb_code=replace(mb_code,"$SecondClass",SecondClass)
'mb_code=replace(mb_code,"$ThirdClasses",ThirdClasses)
'选出新添加的新闻的id
set rsid=server.createobject("adodb.recordset")
sql="select top 1 NewsId from inNews order by NewsId desc"
rsid.open sql,conn,1,3
mb_code=replace(mb_code,"$NewsId",rsid("NewsId"))'替换浏览次数中的编号
rsid.close
set rsid=nothing
%>
MyPagerTable="<table width=""60%"" border=""0"" cellpadding=""0"" cellspacing=""1""><tr><td height=""25""><a href=""$UrlUp""><font color=""ff0000""><strong>[上一页]</strong></font></a></td><td height=""30""><a href=""$UrlDown""><font color=""ff0000""><strong>[下一页]</strong></font></a></td></tr></table>"''''''''''下一页代码,用于替换
if p<=1 then''''''''''分页
MyPagerTable=replace(MyPagerTable,"$UrlUp",fname&".shtml")
if p=PageNumber then
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p&".shtml")
else
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p+1&".shtml")
end if
else
MyPagerTable=replace(MyPagerTable,"$UrlUp",fname&"_"&p-1&".shtml")
if p=PageNumber then
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p&".shtml")
else
MyPagerTable=replace(MyPagerTable,"$UrlDown",fname&"_"&p+1&".shtml")
end if
end if
mb_code=replace(mb_code,"$MyPager",MyPagerTable)
else
mb_code=replace(mb_code,"$MyPager","")
end if
'mb_code=replace(mb_code,"$FirstClass",FirstClass)
'mb_code=replace(mb_code,"$SecondClass",SecondClass)
'mb_code=replace(mb_code,"$ThirdClasses",ThirdClasses)
'选出新添加的新闻的id
set rsid=server.createobject("adodb.recordset")
sql="select top 1 NewsId from inNews order by NewsId desc"
rsid.open sql,conn,1,3
mb_code=replace(mb_code,"$NewsId",rsid("NewsId"))'替换浏览次数中的编号
rsid.close
set rsid=nothing
%>
<%'生成HTML页面
'Set fso = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next '容错处理
fso.CreateFolder(Server.MapPath(folder))
if p=0 then
Set fout = fso.CreateTextFile(Server.MapPath(filepath&".shtml"))
else
Set fout = fso.CreateTextFile(Server.MapPath(filepath&"_"&p&".shtml"))
end if
fout.WriteLine mb_code
fout.close
next
%>
'Set fso = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next '容错处理
fso.CreateFolder(Server.MapPath(folder))
if p=0 then
Set fout = fso.CreateTextFile(Server.MapPath(filepath&".shtml"))
else
Set fout = fso.CreateTextFile(Server.MapPath(filepath&"_"&p&".shtml"))
end if
fout.WriteLine mb_code
fout.close
next
%>