动态网站页面的静态生成方法.doc

上传人:bao****ty 文档编号:132223074 上传时间:2020-05-13 格式:DOC 页数:13 大小:50KB
返回 下载 相关 举报
动态网站页面的静态生成方法.doc_第1页
第1页 / 共13页
动态网站页面的静态生成方法.doc_第2页
第2页 / 共13页
动态网站页面的静态生成方法.doc_第3页
第3页 / 共13页
动态网站页面的静态生成方法.doc_第4页
第4页 / 共13页
动态网站页面的静态生成方法.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《动态网站页面的静态生成方法.doc》由会员分享,可在线阅读,更多相关《动态网站页面的静态生成方法.doc(13页珍藏版)》请在金锄头文库上搜索。

1、动态网站页面的静态生成方法方法一:程序代码%常用函数1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码function getHTTPPage(url)dim Httpset Http=server.createobject(MSXML2.XMLHTTP)Http.open GET,url,falseHttp.send()if Http.readystate4 then exit functionend ifgetHTTPPage=bytesToBSTR(Http.responseBody,UTF-8)set http=nothingif err.number0

2、then err.Clear end function2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换Function BytesToBstr(body,Cset)dim objstreamset objstream = Server.CreateObject(adodb.stream)objstream.Type = 1objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Char

3、set = CsetBytesToBstr = objstream.ReadText objstream.Closeset objstream = nothingEnd Function txtURL=server.MapPath(./index.asp)sText = getHTTPPage(txtURL) Set FileObject=Server.CreateObject(Scripting.FileSystemObject) filename=./index.htmSet openFile=FileObject.OpenTextfile(server.mapPath(filename)

4、,2,true) true为不存在自行建立openFile.writeline(sText)Set OpenFile=nothing此处也可以不用FSO,而用ADO.STREAM,如下这个函数Function SaveToFile(strBody,ByVal File,CharSet)if CharSet = then CharSet = GB2312Dim objStreamSet objStream = Server.CreateObject(ADODB.Stream)With objStream.Type = 2.Open.Charset = CharSet.Position = obj

5、Stream.Size.WriteText = strBody.SaveToFile Server.MapPath(File),2.CloseEnd WithSet objStream = NothingEnd Function%alert(静态网页生成完毕);history.back();方法二:程序代码resourcefile=server.MapPath(./index.asp)targetfile=server.MapPath(./index.htm)Set html = Server.CreateObject(CDO.Message)html.CreateMHTMLBody reso

6、urcefile,31 indexcode=html.HTMLBodySet html = Nothingif instr(indexcode,)=0 thenresponse.Write(首页生成失败)response.End()elseSet oFileSys = Server.CreateObject(Scripting.FileSystemObject)Set outfile=oFileSys.CreateTextFile(targetfile)outfile.WriteLine indexcodeoutfile.close Set outfile=nothingset oFileSy

7、s=nothingresponse.Write(首页生成完毕!)end if(二)Asp生成HTML方法一:FSOSet fs = CreateObject(Scripting.FileSystemObject)NewFile=Server.MapPath(/asp/chap06/at/newfile.html)新建一文件/newfile.html,若该文件已存在,则覆盖它Set a = fs.CreateTextFile(NewFile, True)Response.Write新文件已建立!a.closeFile=Server.MapPath(newfile.html)Set txt=fs.

8、OpenTextFile(File,8,True) 打开成可以在结尾写入数据的文件data1=这句话是使用WriteLine方法写入的哦!txt.WriteLine data1data2=这句话是使用Write方法写入的哦!txt.Write data2txt.Close方法二:XMLHTTP%Set xml = Server.CreateObject(Microsoft.XMLHTTP)把下面的地址替换成你的首页的文件地址,一定要用http:/开头的绝对路径,不能写相对路径xml.Open GET, http:/ Falsexml.SendBodyText=xml.ResponseBodyB

9、odyText=BytesToBstr(BodyText,gb2312)Set xml = NothingDim fso, MyFileSet fso = CreateObject(Scripting.FileSystemObject)Set MyFile= fso.CreateTextFile(server.MapPath(aa.htm), True)MyFile.WriteLine(BodyText)MyFile.Close其他:1下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index

10、2.htm,index3.htm存在根目录下面:%dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_TempHtml_Temp=For i=1 To 3Html_Temp = Html_Temp&Item_Classid = iFileName = Index&Item_Classid&.htmFilePath = Server.MapPath(/)&FileName Html_Temp = Html_Temp&FilePath&Do_Url = http:/Do_Url = Do_Url&Request.ServerVariab

11、les(SERVER_NAME)&/main/index.aspDo_Url = Do_Url&?Item_Classid=&Item_ClassidstrUrl = Do_Urldim objXmlHttpset objXmlHttp = Server.createObject(Microsoft.XMLHTTP)objXmlHttp.open GET,strUrl,falseobjXmlHttp.send()Dim binFileDatabinFileData = objXmlHttp.responseBodyDim objAdoStreamset objAdoStream = Serve

12、r.createObject(ADODB.Stream)objAdoStream.Type = 1objAdoStream.Open()objAdoStream.Write(binFileData)objAdoStream.SaveToFile FilePath,2objAdoStream.Close()NextHtml_Temp = Html_Temp&%Response.Write ( 成功生成文件: )Response.Write ( )Response.Write Html_Temp%Function BytesToBstr(body,Cset)dim objstreamset obj

13、stream = Server.CreateObject(adodb.stream)objstream.Type = 1objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Charset = CsetBytesToBstr = objstream.ReadTextobjstream.Closeset objstream = nothingEnd Function%2%public tempelatefile,tmpdatasub ofile()打

14、开文件,并把文件内容放到tmpdataon error resume nexttmpdata=set Astream=Server.CreateObject (Adodb.Stream)Astream.type=2文件类型文本Astream.Mode = 3读写Astream.openAstream.CharSet = GB2312字符集Astream.LoadFromFile(tempelatefile)从文件装载Assp=Astream.sizeif err.number0 thenxz=-18response.Write tempelatefile&err.cleartmpdata=elsetmpdata=Astream.ReadText(Assp)end ifend subsub save_file()ofile()recfilen=server.MapPath(dts)Astream.FlushAstream.closeAstream.type=2Astream.Mo

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号