asp 生成静态问题

jinx151 2008-04-30 11:19:45
看到过生成的静态的方法:
模板跟replace 进行替换.用FSO进行生成.
简单的,例如新闻标题,内容,时间等直接替换即可.
但复杂点(比如代码有循环,asp代码不断穿插),确有不知如何进行处理:
---------------------------------------------

<table width="95%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF">
<td width="25%" rowspan="2" align="center">手机型号</td>
<td height="20" colspan="3" align="center" bgcolor="#efeded"><strong>对应电池型号</strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="25%" height="25" align="center">
<%if name1="商务版手机电池" then
response.write("<font color=#44ae8a><b>商务版手机电池</b></font>")
else
response.write("商务版手机电池")
end if %></td>
<td width="26%" align="center">
<%if name1="商业版手机电池" then
response.write("<font color=#44ae8a><b>商业版手机电池</b></font>")
else
response.write("商业版手机电池")
end if %> </td>
<td width="24%" align="center">
<%if name1="普及版手机电池" then
response.write("<font color=#44ae8a><b>普及版手机电池</b></font>")
else
response.write("普及版手机电池")
end if %></td>
</tr>
<%xhsql="select sjxhname from sjxh where smallclassname='"&name3&"' and bigclassname='"&name1&"' order by id desc"
set xhrs=server.createObject("adodb.recordset")
xhrs.open xhsql,conn,1,1
while not xhrs.eof
chsql="select articleid,title from product where smallclassname='"&name3&"' and bigclassname='"&name1&"' and sjxhname like '%"&xhrs("sjxhname")&"%' and passed=1 order by articleid"
set chrs=server.createObject("adodb.recordset")
chrs.open chsql,conn,1,1
if not chrs.eof then
%>
<tr bgcolor="#FFFFFF">
<td height="25" align="center"><%=xhrs("sjxhname")%></td>
<td align="center"><%
while not chrs.eof
chtitle=chrs("title")
response.write("<a href=prdinfo.asp?name="&name&"&name1="&name1&"&name3="&name3&"&name4="&chtitle&"&id="&chrs("articleid")&" class=zt><font color=#ff6633>"&chtitle&"</font></a><br>")
chrs.movenext
wend%></td>
<td align="center"><%sysql="select articleid,title from product where smallclassname='"&name3&"' and bigclassname='商业版手机电池' and sjxhname like '%"&xhrs("sjxhname")&"%' and passed=1 order by articleid"
set syrs=conn.execute(sysql)
while not syrs.eof
sytitle=syrs("title")
response.write("<a href=prdinfo.asp?name="&name&"&name1="&name1&"&name3="&name3&"&name4="&sytitle&"&id="&syrs("articleid")&" class=zt><font color=#3399ff>"&sytitle&"</font></a><br>")
syrs.movenext
wend
syrs.close
set syrs=nothing
%></td>
<td align="center"><%sysql="select articleid,title from product where smallclassname='"&name3&"' and bigclassname='普及版手机电池' and sjxhname like '%"&xhrs("sjxhname")&"%' and passed=1 order by articleid"
set syrs=conn.execute(sysql)
while not syrs.eof
sy2title=syrs("title")
response.write("<a href=prdinfo.asp?name4="&sy2title&"&id="&syrs("articleid")&" class=zt><font color=#ff6633>"&sy2title&"</font></a><br>")
syrs.movenext
wend
syrs.close
set syrs=nothing
%></td>
</tr>
<%end if
chrs.close
set chrs=nothing
xhrs.movenext
wend
xhrs.close
xhrs=nothing%>
</table>
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
md5e 2008-04-30
  • 打赏
  • 举报
回复
用一个变量

str="<table..."
do wile...
str=str & "<a href=...>" + rs("title") + "</a>"
...

loop
...

okfile = replace(okfile,"#titlename#",webtitle)





'############热点############
hot=""
set rs_u=server.createobject("adodb.recordset")
sql_u="select title,url from happywz_URL where space=6 order by id"
rs_u.open sql_u,conn,1,1
while not rs_u.eof
hot=hot+"<a href='"&rs_u("url")&"' target='_blank' class=""STYLE3"">"&rs_u("title")&"</a> "
rs_u.movenext
wend
rs_u.close
'#########End热点#########

....
'#############在线杀毒########
sql="Select Top 6 wwwurl,wwwweb From happywz_WEB Where wwwsort='在线杀毒' order by isok ,addtime desc,wwwid"
set rs=Conn.Execute(sql)
i=1
Kill="<UL>"
do while not rs.eof
Kill=Kill &"<LI><a href='"&rs("wwwurl")&"' target='_blank'>"&rs("wwwweb")&"</a></LI>"
if i mod 2=0 then Kill=Kill & "</UL><UL>"
i=i + 1
rs.movenext()
Loop
Kill=Kill & "</UL>"
'###########End在线杀毒##########
set rs_u=nothing
hot2=""
set rs_u=server.createobject("adodb.recordset")
sql_u="select title,url from happywz_URL where space=7 order by id"
rs_u.open sql_u,conn,1,1
while not rs_u.eof
hot2=hot2+"<li><a href='"&rs_u("url")&"' target='_blank'>"&rs_u("title")&"</a> </li>"
rs_u.movenext
wend
rs_u.close
set rs_u=nothing
fz=""
set rs_u=server.createobject("adodb.recordset")
sql_u="select title,url from happywz_URL where space=4 order by id"
rs_u.open sql_u,conn,1,1
while not rs_u.eof
fz=fz+"<LI><a href='"&rs_u("url")&"' target='_blank'>"&rs_u("title")&"</a> </LI>"
rs_u.movenext
wend
rs_u.close
set rs_u=nothing
news=""
set rs_url=server.createobject("adodb.recordset")
sql_url="select top 16 wwwid,wwwurl,wwwweb,addtime,isok,hits from happywz_WEB order by wwwid desc"
rs_url.open sql_url,conn,1,1
while not rs_url.eof
news=news&"<LI><A HREF='"&rs_url("wwwurl")&"' TARGET=_blank>"&left(rs_url("wwwweb"),6)&"</A>"&jian&"</LI>"
rs_url.movenext
wend
rs_url.close
set rs_url=nothing
indexhtm=""
set rs_u=server.createobject("adodb.recordset")
sql_u="select sort,sml from happywz_SORT where sortstep=0"
rs_u.open sql_u,conn,1,1
jishu=1
while not rs_u.eof
if jishu/8 mod 2=0 and jishu mod 8 =1 then
indexhtm=indexhtm+"<UL class=bg0>"
elseif jishu mod 8=1 then
indexhtm=indexhtm+"<UL class=bg1>"
end if
indexhtm=indexhtm+"<LI><a href='html/"&rs_u("sml")&".htm'>"&rs_u("sort")&"</a> </LI>"
if jishu mod 8 = 0 then
indexhtm=indexhtm+"</UL>"
end if
jishu=jishu+1
rs_u.movenext
wend
rs_u.close
set rs_u=nothing
service=""
set rs_u=server.createobject("adodb.recordset")
sql_u="select * from happywz_SERVICE where index=0 order by id Desc"
rs_u.open sql_u,conn,1,1
jishu=1
while not rs_u.eof
if jishu mod 4 =1 then
service=service+"<UL class=bg0>"
elseif jishu=1 or jishu mod 2 = 1 then
service=service+"<UL class=bg1>"
end if
service=service+"<LI><a href='service/"&rs_u("id")&".htm'>"&rs_u("name")&"</a> </LI>"
if jishu mod 2 = 0 then
service=service+"</UL>"
end if
jishu=jishu+1
rs_u.movenext
wend
rs_u.close
set rs_u=nothing
'读出模版文件
set rs_2 = server.CreateObject ("Adodb.recordset")
if webv>0 then
sql_2="select * from happywz_DEMO where ifuse=1 and demoid="&webv
else
errmsg=errmsg+"<br>"+"<li>首页模版未绑定或模版丢失,请重新绑定!!</a>!"
call diserror()
response.end
end if
rs_2.open sql_2,conn,1,1
okfile=rs_2("demohtml")
rs_2.close
set rs_2=nothing

'---------替换模板数据
okfile = replace(okfile,"#titlename#",webtitle)
okfile = replace(okfile,"#url#",weburl)
okfile = replace(okfile,"#name#",webname)
okfile = replace(okfile,"#email#",webemail)
okfile = replace(okfile,"#webstat#",webstat)
okfile = replace(okfile,"#memo#",webdescription)
okfile = replace(okfile,"#indexhtm#",indexhtm)
okfile = replace(okfile,"#logo2#",weblogo2)
okfile = replace(okfile,"#keywords#",webkeywords)
okfile = replace(okfile,"#menu#",menu)
okfile = replace(okfile,"#hot#",hot)
okfile = replace(okfile,"#hot2#",hot2)
okfile = replace(okfile,"#fz#",fz)
okfile = replace(okfile,"#service#",service)
okfile = replace(okfile,"#gao#",webgao)
okfile = replace(okfile,"#new#",news)
okfile = replace(okfile,"#Breadcrumbs#",Breadcrumbs)'友情链接
okfile = replace(okfile,"#Usually_1#",Usually_1)'实用工具
okfile = replace(okfile,"#Usually_2#",Usually_2)'实用工具
okfile = replace(okfile,"#Usually_3#",Usually_3)'实用工具
okfile = replace(okfile,"#Usually_4#",Usually_4)'实用工具
okfile = replace(okfile,"#Usually_5#",Usually_5)'实用工具
okfile = replace(okfile,"#HotSearch#",HotSearch)'热点查询
okfile = replace(okfile,"#HotSearchMore#",HotSearchMore)'热点查询更多
okfile = replace(okfile,"#Transportation#",Transportation)'交通旅游
okfile = replace(okfile,"#Finance#",Finance)'金融理财
okfile = replace(okfile,"#Health#",Health)'健康查询
okfile = replace(okfile,"#Study#",Study)'学习应用
okfile = replace(okfile,"#Business#",Business)'商业经济
okfile = replace(okfile,"#Everyday#",Everyday)'日常查询
okfile = replace(okfile,"#Kill#",Kill)'在线杀毒
Set fso = Server.CreateObject(""&fsoset&"")
Set fout = fso.Createtextfile(server.mappath("../index.html"),true)
fout.writeline okfile
fout.close
%>
<td><div align="center"><font color="#0000FF">首页更新完成</font> 地址为默认 <a href="../index.html" target="_blank">../index.html </a></div></td>
</tr><%end if%>
</table>
<TABLE WIDTH="99%" BORDER="0" CELLPADDING="2" CELLSPACING="1" BGCOLOR="#0099CF" align="center">
<TR BGCOLOR="#0099CF"> <TD HEIGHT="22"
COLSPAN="2" align='center'><span class="STYLE2">操作说明</span></TD>
</TR> <TR BGCOLOR="#ffffff"> <TD WIDTH="87" HEIGHT="30"><B>操作说明:</B></TD><TD
HEIGHT="30">
<LI>您只需点击更新首页按钮就可按照你的设定更新首页</TD></TR> </TABLE>

</body>
</html>

银狐被占用 2008-04-30
  • 打赏
  • 举报
回复
表格用程序来输出。
windwl 2008-04-30
  • 打赏
  • 举报
回复
没有
jinx151 2008-04-30
  • 打赏
  • 举报
回复
把其他的代码用程序输出
这种方法可行,但是,这样输出往往很是麻烦.
想问下有没其他方法生成静态

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧