
asp代码生成html,怎样做,哪位高手帮帮忙!谢谢了!急!
3个回答
展开全部
也不是个难事,原理很简单。会用VB做记事本么,实际上跟这个一样,就是做一个保存纯文本文件的功能,调用FSO即可。如下:
<%
Set fso=CreateObject("Scripting.FileSystemObject")
NewFile=Server.MapPath("/html/文件名.html")
'HTML文件的位置
Set t=fso.CreateTextFile(NewFile, True)
t.close
'新建了一个空白的纯文本文件
File=Server.MapPath("/html/文件名.html")
Set txt=fso.OpenTextFile(File,8,True)'打开刚才创建的纯文本文件
txt.Write "<html><head><title>这是一个静态页面</title></head><body>这里就是静态页面的内容了</body></html>"
'写入内容
txt.Close
'OK了,就这么简单
%>
创建的纯文本文件的位置根据你自己需要调整吧,写入到静态页面里的内容也可以加入动态获取的内容,比如从数据库里读取的部分,比如"<title>"&rs("数据库标题")&"</title>"。至于要使静态页面的代码能换行,加入换行符比如"<html>"&chr(13)&chr(10)&"<head>"即可,这样生成出来的HTML页面的代码就错落有致了。
相信你有一定的ASP基础,肯定能看得懂!
<%
Set fso=CreateObject("Scripting.FileSystemObject")
NewFile=Server.MapPath("/html/文件名.html")
'HTML文件的位置
Set t=fso.CreateTextFile(NewFile, True)
t.close
'新建了一个空白的纯文本文件
File=Server.MapPath("/html/文件名.html")
Set txt=fso.OpenTextFile(File,8,True)'打开刚才创建的纯文本文件
txt.Write "<html><head><title>这是一个静态页面</title></head><body>这里就是静态页面的内容了</body></html>"
'写入内容
txt.Close
'OK了,就这么简单
%>
创建的纯文本文件的位置根据你自己需要调整吧,写入到静态页面里的内容也可以加入动态获取的内容,比如从数据库里读取的部分,比如"<title>"&rs("数据库标题")&"</title>"。至于要使静态页面的代码能换行,加入换行符比如"<html>"&chr(13)&chr(10)&"<head>"即可,这样生成出来的HTML页面的代码就错落有致了。
相信你有一定的ASP基础,肯定能看得懂!
展开全部
直接新建一个html网页就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
以下是我常用的将首页静态化的程序,其它页面涉及到很多代码,这儿贴不下。
先用这个静化首页吧
<%
Function GetPage(url)
'获得文件内容
dim Retrieval
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False ', "", ""
.Send
GetPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
Function BytesToBstr(body)
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 = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
on error resume next
Url="index.asp"'要读取的页面地址
response.write "开始更新首页..."
wstr = GetPage(Url)
'response.write(wstr)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'if not MyFile.FolderExists(server.MapPath("/html/")) then
'MyFile.CreateFolder(server.MapPath("/html/"))'
'end if
'要存放的页面地址
dizhi=server.MapPath("index.html")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If
Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>更新完成!</font>"
%>
先用这个静化首页吧
<%
Function GetPage(url)
'获得文件内容
dim Retrieval
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False ', "", ""
.Send
GetPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
Function BytesToBstr(body)
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 = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
on error resume next
Url="index.asp"'要读取的页面地址
response.write "开始更新首页..."
wstr = GetPage(Url)
'response.write(wstr)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'if not MyFile.FolderExists(server.MapPath("/html/")) then
'MyFile.CreateFolder(server.MapPath("/html/"))'
'end if
'要存放的页面地址
dizhi=server.MapPath("index.html")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If
Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>更新完成!</font>"
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询