仙四木剑:ASP生成HTML的问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 13:07:59
网站首页是ASP文件,我想通过一个ASP文件,把首页的ASP生成对应的HTML文件.例如:把index.asp新生成index.htm.内容显示一样的.谢谢大家了!

晕了,
看来高手是多啊
asp生成html方法的确多
你这个建议使用xmlhttp方法,其实非常简单,原理就是将通过iis解析的asp文件另存
代码如下,部分地方自己修改

<%
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
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

Dim Url,Html
Url="http://www.junlens.com"
Html = getHTTPPage(Url)

dim filename,MDBpath,fso,fout
filename="index.htm"
MDBpath="/"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(server.mappath(""&filename&""))
fout.Write html
fout.close
set fout=nothing
set fso=nothing
if err then
response.Write("生成首页失败")
else
response.Write("生成首页成功")
end if
%>

百度一搜一大堆~常用的有两三种方法,比如利用FSO、XMLHTTP等。。

TSYS..二次开发

下面的例子是将、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_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp&"<LI>"
Item_Classid = i
FileName = "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_Classid

strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.createObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFileData
binFileData = objXmlHttp.responseBody
Dim objAdoStream
set objAdoStream = Server.createObject("ADODB.Stream")
objAdoStream.Type = 1
objAdoStream.Open()
objAdoStream.Write(binFileData)
objAdoStream.SaveToFile FilePath,2
objAdoStream.Close()

Next
Html_Temp = Html_Temp&"<UL>"
%>

<%
Response.Write ( "成功生成文件:" )
Response.Write ( "<BR>" )
Response.Write Html_Temp
%>

一楼的搞笑,拿分就拿分嘛,回答这种答案,唉。

反正笑死人不偿命是吧?