日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

动态asp网页批量生成静态html网页问题

發布時間:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 动态asp网页批量生成静态html网页问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<%
'讀取模板
set rs=server.createobject("adodb.recordset")
rs.open ("select tradeinfo_sort from worldec_Temp"),conn,1,1
pencat=rs("tradeinfo_sort")
rs.close
'讀取要生成的條數
? ?if request("page")<>"" then
? ?? ?if cint(request("page"))<1 then
? ?? ?? ?currentPage=1
? ?? ?else
? ?? ?? ?currentPage=cint(request("page"))
? ?? ?end if
? ?else? ?? ???
? ?? ?currentPage=1? ?? ???
? ?end if
? ?
'************** 讀取條數 ***************
? ???MaxPerPage=1
? ???if request("all")="all" then
? ? ? ? set rs=server.createobject("adodb.recordset")
? ???rs.open ("select * from class_1 order by sortID desc"),conn,1,1
? ???end if
? ???if not rs.eof then
? ???rs.pagesize=MaxPerPage
? ???mpage=rs.pagecount? ???'得到總條數
? ???rs.move??(currentPage-1)*MaxPerPage
? ?? ? if mpage>=currentPage then
? ? ? ?? ? ? ? sortid=rs("sortid")
? ? ? ?? ? ? ? sortname=rs("sort")
? ?? ? end if
? ???end if
? ? ? ? rs.close
? ? ? ?
L_BODY=L_BODY&"<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">"
L_BODY=L_BODY&"<TR>"
sqltype="select * from Class_2 where sortid="&sortid&""
set rstype=conn.execute(sqltype)
if rstype.eof then
L_BODY=L_BODY&"<br>No secondary industry classification<br><br>"
else
j=1
do while not rstype.eof
L_BODY=L_BODY&"<TD valign=top align=center>"
L_BODY=L_BODY&"<table border=0 cellspacing=""0"" cellpadding=""2"" width=95%/>"
L_BODY=L_BODY&"<tr><td align=""left"" height=25 valign=top width=2%/><img src=""../../images/icon_4x7_arrow2.gif"" width=""4"" height=""12""></td>"


批量生成靜態頁面
1 info_html.asp
2 info_html_sure.asp

?


info_html.asp
=========================================================
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('網絡超時或您還沒有登陸!');window.location.href='login.asp';</script>"
response.End
else
if session("flag")>1 then
response.Write "<p align=center><font color=red>您沒有此項目管理權限!</font></p>"
response.End
end if
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>批量生成靜態頁面----進度條</title>

<style>
div,body{font-size:12px}
#load{z-index:1;width:500px;height:11px;border:1px #82AF2C solid;}
#loading{position:absolute;z-index:2;height:11px; background-color:#B4C96B; overflow:hidden;}
#div1{position:absolute;z-index:3;width:100%;height:100%;line-height:13px;text-align:center;}
.red_font {color: #FF0000}
.green_font {color: #669900}
</style>
</head>

<body>


<script language="javascript">
//創建XMLHttpRequest對象
var temp_id;
var request = false;
try {
request = new XMLHttpRequest();
}
catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed) {
request = false;
}
}
}
if (!request)alert("Error initializing XMLHttpRequest!");
//獲取信息
function kaishi(btn)
{
btn.disabled = true;
btn.value = "批量生成中..";
document.bg.location.href="info_html_sure.asp";
temp_id=setInterval("getInfo()",1000)
document.getElementById("tong_ji").style.display="";

}
function stop_read()
{
clearInterval(temp_id);
document.getElementById("btn").value="開始批量生成靜態頁面";
document.getElementById("btn").disabled= false;
}
function getInfo() {
var url = "/news_html.txt?id=" + Math.random();
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
//更新頁面
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText.split(",");

document.getElementById("div1").innerText = response[0];
document.getElementById("loading").style.width = response[0];
document.getElementById("now_page").innerText = response[1];
document.getElementById("all_page").innerText = response[2];
if(response[0]=="100.00%")
{
stop_read();

}
}
else if(request.status == 404) {
alert ("Requested URL is not found.");
}
else if (request.status == 403) {
alert("Access denied.");
}
else
alert("status is " + request.status);
}
}
</script>


<table width="511" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="511" height="50">&nbsp;</td>
</tr>

<tr>
<td height="96">&nbsp; <div id="load"><div id="loading"></div><div id="div1">&nbsp;</div>
</div></td>
</tr>
<tr>
<td height="75" align="center" valign="top" class="green_font" id="tong_ji" style="display:none">已生成 <span class="red_font" id="now_page">&nbsp;</span> 頁靜態頁面,共 <span class="red_font" id="all_page">&nbsp;</span> 頁需要生成。</td>
</tr>
<tr>
<td height="30" align="center"><input name="btn" style="border:1px solid #333333;height:25px" type="button" id="btn" value="開始批量生成靜態頁面" οnclick="kaishi(this);" /></td>
</tr>
<tr>
<td height="150" align="center">&nbsp;</td>
</tr>
</table>
<iframe width="0" height="0" id="bg" name="bg" ></iframe>
</body>
</html>

?

?

?

?

?

info_html_sure.asp
==================================================================
<%
if session("admin")="" then
response.Write "<script language='javascript'>alert('網絡超時或您還沒有登陸!');window.location.href='login.asp';</script>"
response.End
else
if session("flag")>1 then
response.Write "<p align=center><font color=red>您沒有此項目管理權限!</font></p>"
response.End
end if
end if


session("help")=int((10-1+1)*Rnd + 1)
server.ScriptTimeout=9999
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
''''''''''''''''''''這里是conn對象打開數據庫的動作,asp代碼需要自己改造,本文不作解釋'''''''''
set conn=server.createobject("adodb.connection")
str="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("/")&"/datec/#mtccc.asp"
conn.open str
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set tp=server.CreateObject("adodb.recordset")
tp.open "select newsid from inform",conn,1,1
if not tp.bof and not tp.eof then
for ixi=1 to tp.recordcount
if not tp.bof and not tp.eof then
call make_html(tp("newsid"))
''''''''''''''''''''''在此往gaga.txt文件寫入進度信息'''''''''''''''''''''''''''''''''''''''''
set temp_fso=Server.CreateObject("Scripting.FileSystemObject")
Set temp_file=temp_fso.OpenTextfile(server.MapPath("/")&"/news_html.txt",2,true) 'true為不存在自行建立
temp_file.writeline(formatnumber((ixi/tp.recordcount)*100,2)&"%,"&ixi&","&tp.recordcount)
Set temp_file=nothing
''''''''''''''''''''''''''''將這些信息以逗號連接在一起,ajax讀取后js再分開'''''''''''''
tp.movenext
else
exit for
end if
next

end if
tp.close
set tp=nothing
function make_html(chuan_id)
temp_id=chuan_id
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from inform where newsid="&temp_id,conn,1,1
if not rs.bof and not rs.eof then

'''''''''''''''''''此處是要生成的靜態頁的地址''''''''''''''''''''''''''''''''''''''''''
txtURL="http://"&Request.ServerVariables("server_name")&"/info_html_jt.asp?id="&temp_id
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sText = getHTTPPage(txtURL)
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename=server.MapPath("/")&"/news/info_"&temp_id&".html"

Set openFile=FileObject.OpenTextfile(filename,2,true) 'true為不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
rs.close
set rs=nothing
end if
end function
function checksql(kustr)
checksql=server.htmlencode(replace(replace(replace(kustr,"<>"," "),"* from "," "),"="," "))
end function
%>

1、ASP兩種簡單的生成靜態首頁的方法

?

為什么要生成靜態首頁?
1、如果你首頁讀取的數據庫次數比較多,速度很慢,而且占用很多服務器資源。使用靜態頁面訪問速度當然快多了
2、搜索引擎容易搜索到
3、如果程序出問題,也能保證首頁能訪問。
4、其他的太多,自己想:) 應用方式:
如果你的首頁是index.asp,你可以生成index.htm (默認訪問順序必須是index.htm,index.asp)。這樣訪問者第一次訪問到你的網站的時候打開的是index.htm 。你可以把網站首頁的鏈接做成index.asp,這樣從網站任何一個頁面點擊首頁的鏈接出現的就是index.asp,這樣保證的信息更新的及時性(畢竟index.htm需要每次手動更新)。 方法一:
直接將首頁文件包含在表單文本框中,將首頁代碼最為數據提交,然后生成靜態頁面。
代碼如下: <%
'------------------------------------------------------------
'使用表單提交生成靜態首頁的代碼
'確保你的空間支持FSO,且首頁代碼內容較少
'------------------------------------------------------------ dim content content=Trim(Request.Form("content"))
if content<>"" then
call makeindex()
end if sub makeindex()
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Filen=Server.MapPath("index.htm")
Set Site_Config=FSO.CreateTextFile(Filen,true, False)
Site_Config.Write content
Site_Config.Close
Set Fso = Nothing
Response.Write("<script>alert('已經成功生成首頁!')</script>")
end sub
%>
<form name="form1" method="post" action="">
<textarea name="content">
<!-- #i nclude file="index.asp" -->
</textarea>
<br>
<input type="submit" name="Submit" value="提交">
</form> 缺點:
1、如果首頁中包括<@ ..>標記,會提示出錯。
2、如果首頁代碼較長,用表單無法提交過去(表單數據長度有一定的限制)。
解決方案:
1、去掉index.asp中的<@ >標記
2、使用eWebEditor,提交支持大數據(能自動分割)
優點:
可以在生成時對內容實時修改。 方法二:
直接使用XMLHTTP獲取index.asp的代碼
<%
'----------------------------------------------------------
'使用XMLHTTP生成靜態首頁的代碼
'Curl 為你的首頁地址,確保你的空間支持FSO
'----------------------------------------------------------- dim read,Curl,content Curl="http://www.xx0123.com/index.asp"
read=getHTTPPage(Curl) if read<>"" then
content=read
call makeindex()
end if sub makeindex()
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Filen=Server.MapPath("index.htm")
Set Site_Config=FSO.CreateTextFile(Filen,true, False)
Site_Config.Write content
Site_Config.Close
Set Fso = Nothing
Response.Write("<script>alert('已經成功生成首頁!')</script>")
end sub Function getHTTPPage(url)
dim http
set http=Server.createobject("Microsoft.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
%>

2、模板分離批量生成

模板文件中要替換的內容均以{...}括起來

為力求簡潔,去掉了錯誤處理代碼(replace中要來替換的字符串參數不能為null值,當然fso也應該做錯誤檢查)。
<%
' ---------------------------------------------------------------------------------------------------------------------
' 出自: kevin fung http://www.yaotong.cn
' 作者: kevin fung 落伍者ID:kevin2008,轉載時請保持原樣
' 時間: 2006/07/05落伍者論壇首發
' ----------------------------------------------------------------------------------------------------------------------
Dim start '該變量為指針將要指向的記錄集位置,通過參數動態獲得
Dim Template '模板文件將以字符串讀入該變量
Dim content '替換后的字符串變量
Dim objConn '連接對象
Dim ConnStr '連接字符串
Dim sql '查詢語句
Dim cnt:cnt = 1 '本輪循環計數器初始化

start = request("start") '獲取本輪指針的開始位置
If IsNumeric(start) Then start = CLng(start) Else start=1
If start=0 Then start = 1 '如果start

ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath("DataBase.mdb")
sql = "select * from table_name"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open ConnStr

set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,objConn,1,1 '打開數據集
rs.AbsolutePosition = start '最關鍵的一步,將指針指向start,start通過參數動態獲得

Template = getTemplate(Server.MapPath("template.html"))' template.html為模板文件,通過函數getTemplate讀入到字符串,模板文件中要替換的內容均以{...}括起來

While Not rs.eof And cnt<= 500 '500是設定一次請求生成頁面的循環次數,根據實際情況修改,如果太高了,記錄集很多的時候會出現超時錯誤
content = Replace(Template,"{filed_name_1}",rs("filed_name_1")) '用字段值替換模板內容
content = Replace(content,"{filed_name_2}",rs("filed_name_2"))
......
content = Replace(content,"{filed_name_n}",rs("filed_name_n"))

genHtml content,Server.MapPath("htmfiles/"&rs("id")&".html") '將替換之后的Template字符串生成HTML文檔,htmfiles為存儲靜態文件的目錄,請手動建立

cnt = cnt + 1 '計數器加1
start = start + 1 '指針變量遞增
rs.movenext
wend

If Not rs.eof Then '通過刷新的方式進行下一輪請求,并將指針變量start傳遞到下一輪
response.write "<meta http-equiv='refresh' content='0;URL=?start="&start&"'>"
Else
response.write "生成HTML文件完畢!"
End if

rs.Close()
Set rs = Nothing
objConn.Close()
Set objConn = Nothing

Function getTemplate(template)'讀取模板的函數,返回字符串,template為文件名
Dim fso,f
set fso=CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile(template)
getTemplate=f.ReadAll
f.close
set f=nothing
set fso=Nothing
End Function

Sub genHtml(content,filename)'將替換后的內容寫入HTML文檔,content為替換后的字符串,filename為生成的文件名
Dim fso,f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile(filename,true)'如果文件名重復將覆蓋舊文件
f.Write content
f.Close
Set f = Nothing
set fso=Nothing
End Sub
%>

?

ASP靜態化后,靜態html頁面點擊計數解決方法

實現方法很簡單,通過在html頁面放置代碼<script type="text/javascript" src="計數器.asp"></script>即可,具本如下:

假設有個news的表,有一字段id,每一條新聞對應1個id.另有一個hit字段,用來統計被點次數。

1、在你要統計點擊次數的html頁面,加入以下代碼(這里count.asp與本文件同錄目)
<script type="text/javascript" src="count.asp?id=新聞相應的IP"></script>?? '這里若你是從ASP靜態化成HTML的,那新聞相應的IP如通過調動數據庫自動填,使用很方便

2、將下面的代碼保存成count.asp
<!--#include file="conn.asp"-->??????? ***這里創建數據庫連接,自已搞了
totalhits=0
<%
sql="select * from news where id="&request.querystring("id")?? '按get來的id搜索相應記錄
set rst=server.CreateObject("adodb.recordset")
rst.open sql,conn,1,3
rst("hit")=rst("hit")+1
rst.update
%>

totalhits=<%=rst("hit")%>


<%rst.close
set rst=nothing
%>

document.write (totalhits)???? ***這句是需要在當前頁面位置輸出點擊數值才用


本站靜態化后,就是通過這樣實現點擊統計的。

總結

以上是生活随笔為你收集整理的动态asp网页批量生成静态html网页问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。