高手看看我这个 asp转html 带分页的 代码 效率好不好
高手看看我这个 asp转html 带分页的 代码 效率好不好 高手有更好的办法没 总觉的这个慢 我这个是发一个新的记录 就要重新生产所有的发页页面
比如总共3页 index1.html index2.html index3.html
要是我新加记录出现index4.html 1 2 3 4我都要重新生产一遍
首先是 添加保存的代码如下
<!--#include file="conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
sql="select * from xw"
rs.open sql,conn,1,3
rs.addnew
rs("bt")=request.Form("bt")
rs("nr")=request.Form("nr")
rs("xh")=request.Form("xh")
rs("sjh")=request.Form("sjh")
rs.update
rs.close
set rs=nothing
response.Redirect("html2.asp?id="&request.Form("sjh")&"") //sjh 就是要生产的页面名称
%>
下面是html2.asp的代码
<!--#include file="conn.asp"-->
<%
Function GetPage(url)
'获得文件内容
dim Retrieval
Set Retrieval = server.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="http://localhost:90/html/xx.asp?id="&request.QueryString("id")&""'要读取的页面地址
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("jt/"&request.QueryString("id")&".html")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If
Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
crfi.close
fs.close
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>"&request.QueryString("id")&"更新完成!</font>"
sql="select * from xw"
set rs=server.createObject("ADODB.Recordset")
rs.open sql,conn,1,1
rs.pagesize=3
zh=rs.pagecount
rs.close
set rs=nothing
response.Redirect("htmlpage.asp?id="&zh&"") //这个是吧 数据库中的总分页数传给 下个页面
%>
下面是htmlpage.asp的代码
<%
Function GetPage(url)
'获得文件内容
dim Retrieval
Set Retrieval = Server.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
aa=request.QueryString("id") //这里循环生产所有分页的页面
for count=1 to aa
on error resume next
Url="http://localhost:90/html/indexqq.asp?page="&count&""'要读取的页面地址
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("jt/index-"&count&".html")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If
Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
crfi.close
fs.close
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>index-"&count&".html更新完成!</font><br>"
%>
<%
next
%>