您的位置:首页 > 编程语言 > ASP

Asp生成静态页的方法总结

2007-01-16 17:30 477 查看
1:模板替换方法
原理就是做一个模板文件放到目录里或将模板文件的代码保存到数据库里,当添加、修改数据或者批量生成的时候用FSO读取模板文件的内容,将其中的特殊字符替换成相应的内容然后写成一个文件保存到目录里就可以了。
2:用xmlHttp对象读取动态执行结果
做好前台的动态页面,页面需要传入一个参数以便到数据库中读取相应的内容,当添加、修改数据或者批量生成的时候用函数读取动态页面执行后的页面内容,然后写成一个文件保存到目录里就可以了。
Function GetPage(url)
'On Error Resume Next
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
3:在多行文本框里执行动态模板页面
让动态文件的执行结果放到多行文本框里并使其隐藏,将其做为表单内容提交,在处理程序中将接收到的文件内容写成一个文件存放到目录里。这种方法比较适合于不用接受参数的动态页面,比如友情链接、产品中心等。
<Form name="go" method="POST" action="default.asp">
<td width="132">
<table width="100%" border="0">
<tr>
<td><input type="submit" style="width:120" name="Submit" value="点击生成友情链接页"></td>
</tr>
<tr style="display:none">
<td><textarea name="word" id="word"><!--#include file="../../link_w.asp"--></textarea></td>
</tr>
</table>

</td>
</FORM>
<%
filename="../../link_w.html"
if request("word")<>"" then
set fso = Server.CreateObject("Scripting.FileSystemObject")
set fout = fso.CreateTextFile(server.mappath(""&filename&""))
fout.write request.form("word")
fout.close
set fout=nothing
set fso=nothing
response.write "生成文字链接页成功!<a href=../../link_w.html target=blank>查看</a>"
end if
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: