12月16, 2011

asp生成html方法

上次说到 asp生成Html缓存问题 ,这里说下怎么用 asp生成html,下面使用的是xmlhttp来获取动态内容,然后用FSO来生成文件。

asp生成html代码:

dim read,reada,Curl,Curla,content,contenta
Function getHTTPPage(url) 
dim http 
set http=Server.createobject("Microsoft.XMLHTTP") 
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then
exit function 
end if 
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
On Error Resume Next
if err.number<>0 then err.Clear 
End function
Function BytesToBstr(body,Cset) 
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText 
objstream.Close
set objstream = nothing
End Function
url1=Request.ServerVariables("Server_name")
Curl="http://"&url1&"/index.asp?a="&now()&""
read=getHTTPPage(Curl) 
if read<>"" then
content=read
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Filen=Server.MapPath("index.html")
Set Site_Config=FSO.CreateTextFile(Filen,true, False)
Site_Config.Write content
Site_Config.Close
Set Fso = Nothing
Response.Write("已经生成主页")
end if

以上代码为asp生成主页HTML,或者单个文件HTML。

代码解释:

url1 是获取当前地址栏的域名,比如本地浏览的时候为http://127.0.0.1/那么他就是127.0.0.1

Curl是获取出来的域名加上你的动态文件地址,这里为index.asp后面加个a=now()是为了杜绝缓存设置的。

Filen是生成到为什么文件,这里是index.html,这个支持相对路径,比如生成为上一个目录的html,那么这样写="../index.html"

下次在发表用asp生成列表和内页HTML,敬请关注

QQ463004799

本文链接:https://xuexb.com/post/asp_html.html

-- EOF --

发表于 2011年12月16日 15:23:59 ,添加在分类 后端技术 下 ,并被添加「 asp 」标签 ,最后修改于 2017年04月19日 11:56:00

提醒: 本文最后更新于 3189 天前,文中所描述的信息可能已发生改变,请谨慎使用。

Comments

评论加载中...

注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理。

AltStyle によって変換されたページ (->オリジナル) /