<body>
<%
if request(“act”)=”ok” then
mbStr=request(“mbstr”)
set fso=createobject(“scripting.filesystemobject”)
set fw=fso.createtextfile(server.mappath(“/index.htm”),true)
fw.writeline mbStr
fw.close
set fso=nothing
response.Write(“首页生成完成”)
else
%>
<form name=”form1″ method=”post” action=”?act=ok”>
<input type=”submit” name=”Submit” value=” 生 成 首 页 ”>
<textarea name=”mbstr” rows=”40″ id=”mbstr” style=”width:100% ”>
<!–#include file=”index.asp”–>
</textarea>
</form>
<%
end if
%>
</body>
</html>
ASP动态网站生成静态首页的方法
‘2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
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
txtURL=server.MapPath(“../index.asp”)
sText = getHTTPPage(txtURL)
Set FileObject=Server.CreateObject(“s cripting.FileSystemObject”)
filename=”../index.htm”
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) ’true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
%>
<s cript>
alert(“静态网页生成完毕”);
history.back();
</s cript>
方法二:
resourcefile=server.MapPath(“../index.asp”)
targetfile=server.MapPath(“../index.htm”)
Set html = Server.CreateObject(“CDO.Message”)
html.CreateMHTMLBody resourcefile,31
indexcode=html.HTMLBody
Set html = Nothing
if instr(indexcode,”</BODY></HTML>”)<=0 then
response.Write(“首页生成失败”)
response.End()
else
Set oFileSys = Server.CreateObject(“s cripting.FileSystemObject”)
Set outfile=oFileSys.CreateTextFile(targetfile)
outfile.WriteLine indexcode
outfile.close
Set outfile=nothing
set oFileSys=nothing
response.Write(“首页生成完毕!”)
end if
ASP两种简单的生成静态首页的方法
为什么要生成静态首页?
1、如果你首页读取的数据库次数比较多,速度很慢,而且占用很多服务器资源。使用静态页面访问速度当然快多了
2、搜索引擎容易搜索到
3、如果程序出问题,也能保证首页能访问。
4、其他的太多,自己想:)
应用方式:
如果你的首页是index.asp,你可以生成index.htm (默认访问顺序必须是index.htm,index.asp)。这样访问者第一次访问到你的网站的时候打开的是index.htm 。你可以把网站首页的链接做成index.asp,这样从网站任何一个页面点击首页的链接出现的就是index.asp,这样保证的信息更新的及时性(毕竟index.htm需要每次手动更新)。
方法一:
直接将首页文件包含在表单文本框中,将首页代码最为数据提交,然后生成静态页面。
代码如下:
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”>
<!– #include file=”index.asp” –>
</textarea>
<br>
<input type=”submit” name=”Submit” value=”提交”>
</form>
缺点:
1、如果首页中包括< @ ..>标记,会提示出错。
2、如果首页代码较长,用表单无法提交过去(表单数据长度有一定的限制)。
解决方案:
1、去掉index.asp中的< @ >标记
2、使用eWebEditor,提交支持大数据(能自动分割)
优点:
可以在生成时对内容实时修改。
方法二:
直接使用XMLHTTP获取index.asp的代码
dim read,Curl,content
Curl=”http://www.gannyle.cn/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&nb
sp;= 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
%>






最新评论
春节快乐啊^_^兄弟
呵呵,路过,顶一下。
老衲已阅
不错的站,路过看下
来拜访啦,呵呵,留名纪念
闲逛到此,留下印记。顶一下。
路过~~留痕
多少支持一下