asp网页如何做成html,实现ASP生成HTML静态页面及分页方法

相关变量参数: strDir 用于保存.html文件的文件夹路径 htmlwrite FSO对象,用于生成.html文件 arrcontent

按分页标签分割的文章内容数组 InnerPageNum 统计内容的页数 rollnum 当前第(rollnum+1)页 pagelist 分页页码

strTemplate 存放模板内容 strTe

1、相关变量参数:

strDir 用于保存.html文件的文件夹路径

htmlwrite FSO对象,用于生成.html文件

arrcontent 按分页标签分割的文章内容数组

InnerPageNum 统计内容的页数

rollnum 当前第(rollnum+1)页

pagelist 分页页码

strTemplate 存放模板内容

strTemp 模板内容备份

$page_break$ 内容分页标签

2、核心代码

'========生成内容静态页======

on Error resume next

Set fso = Server.CreateObject("Scripting.FileSystemObject")

'=====用于保存静态文件的文件夹路径名称,这里我按自己的项目设定了====

strDir=SITEROOT&"/"&NewsHtmlFile&"/"&year(now)&"-"&month(now)

'======生成静态文件保存文件夹=====

if not fso.folderexists(Server.MapPath(strDir)) then

fso.CreateFolder(Server.MapPath(strDir))

set fso=Nothing

if Err=0 then

Dim fso,htmlwrite

,arrcontent,InnerPageNum,rollnum,pagelist,strTemplate,strTemp

'===读取模板文件,我前面的文章关于ASP生成静态的,有这个数据表的内容===

sql="SELECT tp_content FROM [KrTemplate] WHERE tp_default=1 AND

tp_type='新闻内容页模板'"

Set rs=Conn.Execute(sql)

if not rs.eof then

strTemplate=rs(0)

end if

rs.close

'======备份模板文件,避免模板文件被改写=====

strTemp=strTemplate

'======文章数据表=====

sql="SELECT * FROM [KrNews] WHERE news_html=0 ORDER BY news_date DESC"

Set rs=Conn.Execute(sql)

'======循环读取所有要生成的文章信息======

do while not rs.eof

news_keywords=rs("news_keywords")

news_content=rs("news_content")

news_tips=rs("news_tips")

news_name=rs("news_name")

news_from=rs("news_from")

news_date=rs("news_date")

news_id=rs("news_id")

'====匹配文章内容,如果出现分页标签,则按如下处理,否则按普通生成方法处理===

if Instr(news_content,"$page_break$") then

'===如果文章URL要存入数据库,那么这里存入的地址就为文章分页后的第一页的路径,

'===即为下面的URL地址加上第一页的标志,我这里存入数据库的地址是这样的

' ===URL=URL&"_1.html"

URL=SITEURL&strDir&"/news_"&news_id&""

'======对分页信息的预处理=======

'=====将按分页标签分割的文章内容存入数组arrcontent=====

arrcontent=split(news_content,"$page_break$")

'=====得到文章分割后所得的页数=====

InnerPageNum=ubound(arrcontent)

pagelist=" "

'=====循环得到页码======

for rollnum=0 to InnerPageNum

pagelist=pagelist & "["&(rollnum+1)&"] "

next

for rollnum=0 to InnerPageNum

'======还原被改写的模板,这里不注意会生成相同的文件======

strTemplate=strTemp

strTemplate=Replace(strTemplate,"$keywords$",news_keywords)

strTemplate=Replace(strTemplate,"$news_tips$",news_tips)

………… '略,其他一样写法

'===替换文章内容,并添加分页页码====

strTemplate=Replace(strTemplate,"$news_content$",arrcontent(rollnum)&"

分页:"&pagelist&"

")

'====要生成的HTML页面路径及名称======

Address=strDir&"/news_"&news_id&"_"&(rollnum+1)&".html"

'======调用adodb.stream方法生成静态页面,此为自定义方法,附在文章后面===

WriteToTextFile Address,strTemplate

'======(可选择)FSO方法生成静态页面

' Set fso = Server.CreateObject("Scripting.FileSystemObject")

' Set htmlwrite=fso.CreateTextFile(Server.MapPath(Address),true) '//

创建要生成的静态页

' htmlwrite.WriteLine strTemplate '// 写入网页内容

' htmlwrite.close

' set htmlwrite=Nothing

' set fso=Nothing

next

else

strTemplate=Replace(strTemplate,"$keywords$",news_keywords)

strTemplate=Replace(strTemplate,"$news_tips$",news_tips)

strTemplate=Replace(strTemplate,"$sitename$",SITENAME)

…………

strTemplate=Replace(strTemplate,"$news_content$",news_content)

Address=strDir&"/news_"&rs("news_id")&".html"

WriteToTextFile Address,strTemplate

end if

rs.movenext

loop

rs.close

end if

'=======ADODB.Stream生成文件函数=========

Sub WriteToTextFile (FileUrl,byval Str)

set stm=server.CreateObject("adodb.stream")

stm.Type=2 '以本模式读取

stm.mode=3

stm.charset="GB2312"

stm.open

stm.WriteText str

stm.SaveToFile server.MapPath(FileUrl),2

stm.flush

stm.Close

str=""

set stm=nothing

End Sub

asp生成html源码 <% function chan_time(shijian)'转换日期时间函数 s_year=year(shijian) if len(s_year)=2 then s_year="20"&s_year s_month=month(shijian) if s_month<10 then s_month="0"&s_month s_day=day(shijian) if s_day<10 then s_day="0"&s_day s_hour=hour(shijian) if s_hour<10 then s_hour="0"&s_hour s_minute=minute(shijian) if s_minute<10 then s_minute="0"&s_minute chan_time=s_year & s_month & s_day & s_hour & s_minute end function function chan_data(shijian) '转换日期时间函数 s_year=year(shijian) if len(s_year)=2 then s_year="20"&s_year s_month=month(shijian) if s_month<10 then s_month="0"&s_month s_day=day(shijian) if s_day<10 then s_day="0"&s_day chan_data=s_year & s_month & s_day end function function chan_file(shijian)'转换日期时间函数 s_month=month(shijian) if s_month<10 then s_month="0"&s_month s_day=day(shijian) if s_day<10 then s_day="0"&s_day s_hour=hour(shijian) if s_hour<10 then s_hour="0"&s_hour s_minute=minute(shijian) if s_minute<10 then s_minute="0"&s_minute s_ss=second(shijian) if s_ss<10 then s_ss="0"&s_ss chan_file = s_month & s_day & s_hour & s_minute & s_ss end function top="<html><head><title>news</title><meta http-equiv=Content-Type content=text/html; charset=gb2312></head><body>" botom="</body></html>" msg=request.Form("msg") msg=replace(msg,vbcrlf,"") msg=replace(msg,chr(9),"") msg=replace(msg," "," ") msg=replace(msg,"\r\n","<br>") msg=replace(msg,"\n","<br>") msg=top&msg;&botom; Set fs=Server.CreateObject("Scripting.FileSystemObject") all_tree2=server.mappath("news")&"\"&chan;_data(now) if (fs.FolderExists(all_tree2)) then'判断今天的文件夹是否存在 else fs.CreateFolder(all_tree2) end if pass=chan_file(now) randomize '使用系统计时器来初始化乱数产生器 pass=rnd(pass) pass=get_pass(pass) pass=left(pass,10) file1=pass files=file1&".txt" filez=all_tree2&"\"&files; set ts = fs.createtextfile(filez,true) '写文件 for z=1 to len(msg) write_now=mid(msg,z,1) ts.write(write_now) next ' ts.writeline(all_msg) ts.close set ts=nothing '文件生成 if err.number<>0 or err then%> [removed] alert("不能完成") [removed] <%else%> [removed] alert("已完成") history.back(); [removed] <%end if Set MyFile = fs.GetFile(filez) all_tree2=server.mappath("news")&"\"&chan;_data(now) if (fs.FolderExists(all_tree2)) then else fs.CreateFolder(all_tree2) end if MyFile.name= left(MyFile.name,len(MyFile.name)-4)&".html" set MyFile=nothing set fs=nothing set fdir=nothing function get_pass(pass) pass=cstr(pass) pass=replace(pass," ","") pass=replace(pass," ","") pass=replace(pass,"-","") pass=replace(pass," ","") pass=replace(pass,":","") pass=replace(pass,".","") pass=replace(pass,"+","") pass=replace(pass,"_","") pass=replace(pass,"<","") pass=replace(pass,">","") pass=replace(pass,"!","") pass=replace(pass,"@","") pass=replace(pass,"#","") pass=replace(pass,"$","") pass=replace(pass,"%","") pass=replace(pass,"^","") pass=replace(pass,"&","") pass=replace(pass,"*","") pass=replace(pass,"(","") pass=replace(pass,")","") pass=replace(pass,"=","") pass=replace(pass,"\","") pass=replace(pass,"/","") pass=replace(pass,"|","") get_pass=pass end function %>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值