方法一: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.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://www.phpup.com", Falsexml.SendBodyText=xml.ResponseBodyBodyText=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,index2.htm,index3.htm存在根目录下面:<%dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_TempHtml_Temp="<UL>"For i=1 To 3Html_Temp = Html_Temp&"<LI>"Item_Classid = iFileName = "Index"&Item_Classid&".htm"FilePath = Server.MapPath("/")&""&FileName Html_Temp = Html_Temp&FilePath&"</LI>"Do_Url = "http://"Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")&"/main/index.asp"Do_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 = Server.createObject("ADODB.Stream")objAdoStream.Type = 1objAdoStream.Open()objAdoStream.Write(binFileData)objAdoStream.SaveToFile FilePath,2objAdoStream.Close()NextHtml_Temp = Html_Temp&"<UL>"%><%Response.Write ( "成功生成文件:" )Response.Write ( "<BR>" )Response.Write Html_Temp%>Function BytesToBstr(body,Cset)dim objstreamset objstream = 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<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><%public tempelatefile,tmpdatasub ofile()'打开文件,并把文件内容放到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.number<>0 thenxz=-18response.Write tempelatefile&"<br>"err.cleartmpdata=""elsetmpdata=Astream.ReadText(Assp)end ifend subsub save_file()ofile()recfilen=server.MapPath(dts)Astream.FlushAstream.closeAstream.type=2Astream.Mode = 3Astream.openAstream.CharSet = "GB2312"Astream.position=0Astream.Writetext tmpdata,1'写入数据到streamAstream.SaveToFile recfilen,2'保存到文件end subfunction dts()'产生随机文件名if len(month(now()))>1 thenmm=month(now())elsemm="0"&month(now())end ifif len(day(now()))>1 thend=day(now())elsed="0"&day(now())end ifif len(hour(now()))>1 thenh=hour(now())elseh="0"&hour(now())end ifif len(minute(now()))>1 thenm=minute(now())elsem="0"&minute(now())end ifif len(second(now()))>1 thens=second(now())elses="0"&second(now())end ifRandomizeupperbound=9999lowerbound=1000rds=Int((upperbound - lowerbound + 1) * Rnd + lowerbound) dts="htm/"&year(now())&mm&d&h&m&s&rds&".htm"end functiontitle=request.Form("title")content=request.Form("content")tmpdata=replace(tmpdata,"<title></title>",title)'以拥护提交内容替换tmpdata=replace(tmpdata,"<content></content>",content)tempelatefile=server.MapPath("tempelate/1.htm")'模版文件save_file()%>
推荐阅读
同一个帐号不能同时登陆的问题
〓简介〓有点常识的人都知道本身用asp做这种功能显然有些牵强,因为他不像qq,msn或irc 聊天室那样是即时通讯,他都是靠刷新网页更改最后活动时间来获取用户是否在线的,所以您不要指望下面这片教程有多完美,我也>>>详细阅读
本文标题:Asp生成HTML方法大全
地址:http://www.17bianji.com/kaifa2/ASP/33305.html
1/2 1