<%
'读取模板
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网页问题相关推荐

  1. JSP生成静态html网页

    1 /** 2 * jsp生成静态html网页 3 */ 4 public class ToHtml extends HttpServlet { 5 public void service(HttpS ...

  2. PHP 批量生成静态html

    PHP 批量生成静态html|http://bbs.php100.com/read-htm-tid-147570.html 转载于:https://blog.51cto.com/wlq1203/761 ...

  3. 学生个人单页面网页作业 学生网页设计成品 静态HTML网页单页制作 dreamweaver网页设计与制作代码 web前端期末大作业

    HTML实例网页代码, 本实例适合于初学HTML的同学.该实例里面有设置了css的样式设置,有div的样式格局,这个实例比较全面,有助于同学的学习,本文将介绍如何通过从头开始设计个人网站并将其转换为代 ...

  4. ASP动态网页生成静态Html网页代码

    [摘 要] 生成html网页有利于被搜索引擎收录,不仅被收录的快还收录的全.前台脱离了数据访问,减轻对数据库访问的压力,加快网页打开速度. 网页生成静态Html文件有许多好处,比如生成html网页有利 ...

  5. ASP.Net中生成静态HTML页

    越来越多的网站现在将过去的动态网页生成了静态的HTML页,这样做的好处有很多,比如减轻服务器的压力,利于搜索引擎的收录.......在ASP时代利用ADO+FSO将数据库中的内容生成静态的页面,在.N ...

  6. ASP非模板生成静态页

    首先我们要创建一个数据库表news包括字段 id   title     contect     date  接着我们设置一个ASP数据显示页shownew.asp 代码如下: <%@codep ...

  7. 记一次在nuxt中使用generate批量生成静态站点页面

    做过seo的同学都知道,一些不是实时变化的页面(比如一个星期更新一次内容)我们可以生成静态的站点去让爬虫去爬去,这样就无需一次次地调用接口了. 那么在nuxt中我们怎么去做呢? nuxt为我们提供了一 ...

  8. ASP.NET C# 生成静态页面简单方法

    //源码是替换掉模板中的特征字符 string mbPath = Server.MapPath("template.html");             Encoding cod ...

  9. R语者小case之——从KEGG原始网页批量生成通路的基因表格

    我们经常要用到KEGG数据库来对基因做功能分析.经常长得好看的朋友问:如何获得整个通路的基因? 其实我们有多种方法可以获得通路中所有的基因情况,本文通过KEGG的原始网页生成某个通路的基因表格. 准备 ...

最新文章

  1. Deepin系统更新apt-get源
  2. Java throws子句
  3. leetcode - Balanced Binary Tree
  4. autocad软件提供的哪些功能可以提高设计效率?_节省80%制图时间:AutoCAD如何有效“手脑”结合,释放创作潜能?...
  5. JavaFX UI控件教程(十五)之Combo Box
  6. Linux常用错误码--errno-base.h
  7. Vue移动端项目——Vant 移动端 REM 适配
  8. Hibernate 简介
  9. golang中获取公网ip、查看内网ip、检测ip类型、校验ip区间、ip地址string和int转换、根据ip判断地区国家运营商等
  10. docker compose入门
  11. 《上市风云》:每个奋斗者都是一路艰辛
  12. office 365与Visio共存
  13. 微信小程序商品跳转到第三方
  14. 使用Flask部署机器学习模型
  15. java中级工程师所需的技能_java中级工程师岗位职责
  16. 计算机是uefi启动 不能装win7,UEFI引导GPT安装win7方法
  17. 单模光纤和多模光纤的区别,以及作用
  18. 华强北airpods三代连接安卓手机没声音_安卓手机体验华强北的顶配AirPods,“翻车”还是真香?...
  19. java poi导出PPT格式
  20. AndroidJNI 函数介绍

热门文章

  1. 卷积神经网络CNN(Convolutional Neural Networks)没有原理只有实现
  2. 深度学习(十四)基于CNN的性别、年龄识别
  3. 使用docker安装部署Spark集群来训练CNN(含Python实例)
  4. C++,那些可爱的小陷阱(二)
  5. 浅谈尾递归的优化方式
  6. 信息系统项目管理师-知识管理知识点
  7. [译] 解密 Mapbox 卫星影像处理神器 Robosat
  8. win10 uwp 毛玻璃
  9. React-Native学习指南
  10. winform DataGrid排序、去掉第一的空白列