简单生成静态页面办法

80酷酷网    80kuku.com

  最近无意中发现一种简单的办法,比较适合新手,不敢独享,拿出来给大家分享一下。

中心思想就是调用动态模板(也就是你做好ASP网页)。用这种办法可以把几乎所有的ASP网页都变成HTM页,从而实现生成静态页的梦想。

例子:
<textarea name="a" cols="60" rows="6" id="a"><!--#include file="index.asp" --></textarea>

在ASP网页里面直接显示到表单的文本栏里,方便修改。注意:这时候在你文本栏里的index.asp代码已经变成普通的HTM组成的静态页代码了。这时提交表单传到数据库中。

然后的步骤就是:调出数据库的index.asp静态页,利用FSO之类的写入HTM文件中,保存。

如果是新闻发布的话,建议生成STHML文件,就是新浪用那种,就图它可以执行include语句,真是海阔天空任我游啊,举一反三,详细说明。

在数据库建立头部字段,左部,右部,底部(如果你牛X的话可以加上ID字段,以后多做几套模板爱生成啥样生成啥样。),这几个字段一定要TEXT型,因为装的多(就算是新浪的首页多分几块也够用了。)

做好正常的ASP页(注意:你在做ASP页的时候就应该把头,左,右,下都分开做,因为我们调用时是一个一个调用的。),上面是头,左面是新闻内容,右面是新闻列表,下面是底,随便做个HTML模板吧。(不会做的看最后面)

最后:
利用replace的替换大法。

比如先生成头部,要就把模板里的代码替换成数据库里读出的头部字段里存的代码,依次类推,最后把所有取出的代码整合写入HTM文件里面。

友情提示示例代码:
set rs = conn.execute("select * from html")
head = rs("head")
left = rs("left")
right = rs("right")
foot = rs("foot")
rs.close
set rs = nothing
html = head&left&right&foot
没测试,反正就是这个意思。


当然你在生成的时候不可能只生成一条,需要生成多条,我们可以把这个过程当作一个函数,然后:
set rs = server.createobject("adodb.recordset")
sql = "select * from html"
rs.open sql,conn,1,1
do while not rs.eof
call 生成过程函数
rs.movenext
loop
rs.close
set rs = nothing


写到这里忘了一个最重要的东西,晕死,迷迷糊糊都不知道在写些什么。忘了加入文章信息了,汗。。。,不过我想大家都知道应该怎么往里加信息了。我再说就是废话了。


SORRY,我还没说完。


关于HTM模板:

<html>
<head>
<meta name="keywords" content="$keywords$" />
<meta name="description" content="$description$" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>$title$</title>
<style type="text/css">
<!--
body {
       margin-left: 0px;
       margin-top: 0px;
}
body,td,th {
       font-family: 宋体;
       font-size: 12px;
       color: #666666;
}
.newtitle {
       font-size: 14px;
       font-weight: bold;
}
-->
</style></head>

<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" border:#CCCCCC; border-width:1px; border-style:solid">
  <tr>
    <td colspan="2">$head$</td>
  </tr>
</table>
<table height="5"><tr><td></td></tr></table>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="69%" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" border:#CCCCCC; border-width:1px; border-style:solid">
      <tr>
        <td height="60" align="center"><span class="newtitle">$newtitle$</span></td>
      </tr>
      <tr>
        <td><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td>$content$ </td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td height="30">发布时间:$newother$</td>
      </tr>
    </table>
       <table height="5"><tr><td></td></tr></table>
       </td>
    <td width="1%" rowspan="2" align="left" valign="top"> </td>
    <td width="30%" rowspan="2" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"   border:#CCCCCC; border-width:1px; border-style:solid">
      <tr>
        <td align="left" valign="top">$other$</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td align="left" valign="top">
       <table width="100%" border="0" cellspacing="0" cellpadding="0" border:#CCCCCC; border-width:1px; border-style:solid">
      <tr>
        <td height="30">新闻来源:$about$</td>
      </tr>
    </table>
       </td>
  </tr>
  <tr>
    <td colspan="3"> </td>
  </tr>
</table>
<table height="5"><tr><td></td></tr></table>
<tbody>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" border:#CCCCCC; border-width:1px; border-style:solid">
  <tr>
    <td colspan="2">$foot$</td>
  </tr>
</table>
</tbody>
</body>
</html>

其实用不用$符号都无所谓,问题这符号很吉利。


SORRY,还有:

生成页面时容易出现的问题:

如果在网页中含有JAVASCRIPT肯定少不了“‘”(单引号),这个符号SQL跟他有仇,所以我们最好还是用replace的替换大法,把它替换成如"蓝蓝蓝蓝蓝"或"色色色色色"等不容易重复的字符,生成时在把他replace过来.

Text字段虽然装的多但也是有限制的所以适可而止,装太多肯定存不下的.

生成的时候最好不要全部生成,我想绝大多数的网站都是一次生成十几个或几十个页面,所以最好在生成页面加入表单然后让管理员选择想生成的新闻,之后用split函数拆分出需要生成网面的ID.


点一下题:前面我说过的生成STHML文件它不可以包含.ASP文件,要用的话只能用iframe,但可以包含.HTM,说到这里全明白了吧,生成HTM一点不杂复.


最后说一下这种方法生成的较率比较低,但肯定是最适合新手的,我们在租来的空间里千万别乱试,要生成最好在本地生成好然后打包上传到空间里.

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: