asp 由动态网页转变为静态网页的实现代码

在asp中实现由动态网页转变为静态网页可以使用模板生成,通过FsoFile进行操作根据模板生成静态网页,比较适合产品和新闻两个板块转变!

具体代码实现:
1.模板文件(html)
复制代码 代码如下:




{title} - 新闻中心 - 哎呀呀饰品加盟连锁












爱呀呀饰品加盟连锁
















  • 免费热线:4006-888048

    大陆总部:

    总机:0579-89960888

    传真:0579-85210995

    香港总部:

    电话:00852-36458129

    传真:00852-36458092

















  • 新闻中心

    当前位置:首页 - 新闻中心


  • {title}



  • {demo}




















点击进入关于爱呀呀加盟政策 | 装修方案 | 加盟优势 | 产品展示在线留言联系我们网站地图

大陆区地址:浙江省义乌市经济开发区石鱼路123号8栋(稠江中学旁) 大陆区电话:0579-89960888 免费热线:4006-888048



哎呀呀
哎呀呀加盟
哎呀呀饰品




2.处理的文件(asp)
复制代码 代码如下:


<%Server.ScriptTimeOut=99999999%>
<%
dim action,id,news
Layout="news"
id=request.QueryString("id")
action=request.QueryString("action")
select case action
case "add"
%>
<%
'全部生成html
case "htmlall"
set rs=server.CreateObject("adodb.recordset")
Sql = "Select id from news order by id"
rs.open sql,conn,1,1
do while not rs.eof
FsoFile "news",rs("id")
response.write"
"&rs("id")&"新闻生成HTML成功!
"
rs.movenext
loop
rs.close
response.write"
全部新闻生成HTML成功!

"
end select
%>
<%
'生成中文html
Function FsoFile(Layout,ID)
Dim Fso,FilePath,FsoF,FsoH,FsoRs,CreateFilePath
FSOCreateDIR "..\news\" & ID & ""
CreateFilePath = "..\news\" & ID & "" 'HTML所在文件夹
FilePath=Server.Mappath(CreateFilePath) & "\index.html" '定义生成html文件名
Set Fso=Server.CreateObject("Scripting.FileSystemObject")
Set FsoH=Fso.OpenTextFile(Server.Mappath("..\templates\news_show.html"),1,true) '读取模版
Content = FsoH.ReadAll
Set FsoRs = Conn.Execute("select * from news where id="&id)
title=FsoRs("title")
demo=FsoRs("demo")
Content = Replace(Content,"{id}",FsoRs("id"))
Content = Replace(Content,"{title}",FsoRs("title"))
Content = Replace(Content,"{demo}",FsoRs("demo"))
Content = Replace(Content,"{webname}",webname)
Content = Replace(Content,"{icp}",icp)
Content = Replace(Content,"{dianhua}",dianhua)
Content = Replace(Content,"{dizhi}",dizhi)
Content = Replace(Content,"{qq}",qq)
Content = Replace(Content,"{alibaba}",alibaba)
Content = Replace(Content,"{tongji}",tongji)
FsoRs.Close
Set FsoRs=Nothing
set stm = server.createobject("ADODB.Stream")
stm.Charset = "gb2312" '定义编码
stm.Open
stm.WriteText content
stm.SaveToFile FilePath, 2
set stm = nothing
End Function
%>
<%
function FSOCreateDIR(LocalPath)
dim patharr,path_level,i,pathtmp,cpath,CreateDIR,FileObject
on error resume next
LocalPath = Server.MapPath(LocalPath)
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
%>

3.在后台添加生成静态新闻链接
复制代码 代码如下:

来源于我的博客
http://blog.csdn.net/lingfeng179

以上就是asp 由动态网页转变为静态网页的实现代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » ASP编程