求asp生成html文件代码与过程

1首先,如果一个ASP网站都做好了,要把首页生成HTML的,需要多加几个文件,和要修改哪个文件才可以2不知道这里的原理是什么,是要建一个模版,再附上数据库信息还是怎么着,... 1 首先,如果一个ASP网站都做好了,要把首页生成HTML的,需要多加几个文件,和要修改哪个文件才可以
2 不知道这里的原理是什么,是要建一个模版,再附上数据库信息还是怎么着,这个不太清楚.
3. 如果是批量,把网站所以ASP文件全部生成怎么做呢,会不会很麻烦,这样对网站是好是坏呢?
4. 请给了一个简单的例子,比如把我的首页生成静态的,我的首页index.asp里现在只有response.write"11111111111"这样,要怎么写这代码呢?
请问一下,网站全做好了,想实现它我需要做哪个文件,修改哪个文件呢?
展开
 我来答
xiyouyuan
2008-07-01
知道答主
回答量:27
采纳率:0%
帮助的人:8.5万
展开全部
<%
function changechr(str)
changechr=replace(replace(replace(replace(str,"<","<"),">",">"),chr(13),"<br>")," "," ")
changechr=replace(replace(replace(replace(changechr,"[sayyes]","<img src="),"[b]","<b>"),"[red]","<font color=CC0000>"),"[big]","<font size=7>")
changechr=replace(replace(replace(replace(changechr,"[/sayyes]","></img>"),"[/b]","</b>"),"[/red]","</font>"),"[/big]","</font>")
end function

function makefilename(fname)
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
makefilename=fname
end function
%>

<%

if request.form("txttitle")="" then
response.write "错误提示:请输入文章标题!"
response.end
end if
if request.form("txtcontent")="" then
response.write "错误提示:请未输入文章内容!"
response.end
end if
dim title
dim content
dim sql
dim rs
dim articleid
dim classid,Nclassid
dim from

title=request.form("txttitle")
from=request.form("Nfrom")
zznews=request.form("zznews")
typeid=request.form("typeid")
about=request.form("about")

dim sql1
dim rs1
dim typename1
sql1="select * from type where typeid="&typeid
set rs1=server.createobject("adodb.recordset")
rs1.open sql1,conn,1,1
typename1=rs1("type")
filepath=rs1("typename")

if request.form("checkbox1")="1" then
tjnews=1
else
tjnews=2
end if

if request.form("checkbox3")="1" then
selectpic=1
else
selectpic=0
end if

if Session("KEY")="input" then
shenghe=2
else
if request.form("checkbox2")="1" then
shenghe=2
else
shenghe=1
end if
end if

content=changechr(request.form("txtcontent"))
set rs = server.CreateObject("ADODB.RecordSet")
StrSql = "select E_Memo from Example where id="+request("Example")
set rs = conn.Execute (StrSql)
dddd = year(now()) & "年" & month(now()) & "月" & day(now()) & "日" & hour(now())&":"&minute(now())
cat=rs("E_Memo")
fname = makefilename(now())
content=split(content,"H_H")
n=ubound(content)
page1="H_first   H_num<a href='H_ulr1'> 下一页 </a>  H_end"
page2="H_first  <a href='H_ulr2'> 上一页 </a>  H_num  <a href='H_ulr1'> 下一页 </a>  H_end"
page3="H_first  <a href='H_ulr2'> 上一页 </a>  H_numH_end"
for i=0 to n
H_num=H_num&"<a href='"&fname&i&".htm"&"'>"&(I+1)&"</a>  | "
next
for i=0 to n
pname=fname&i&".htm"
pname1=fname&(i+1)&".htm"
pname2=fname&(i-1)&".htm"
H_first="共"&n+1&"页 <a href='"&fname&"0.htm"&"'> 首页 </a>"
H_end="<a href='"&fname&n&".htm"&"'> 尾页 </a>"
pencat=cat

pencat=replace(pencat,"lx",typename1)
pencat=replace(pencat,"Date",dddd)
if from="" then
pencat=replace(pencat,"From","动态网站制作指南")
else
pencat=replace(pencat,"From",from)
end if
if zznews="" then
pencat=replace(pencat,"Fname","SAYYES")
else
pencat=replace(pencat,"Fname",zznews)
end if
pencat=replace(pencat,"H_Title",title)
pencat=replace(pencat,"H_Memo",content(i))
if n=0 then
pencat=replace(pencat,"H_pages","")
elseif n<>0 and i=0 then
pencat=replace(pencat,"H_pages",page1)
pencat=replace(pencat,"H_ulr1",pname1)
elseif n<>0 and i>0 and n-i<>0 then
pencat=replace(pencat,"H_pages",page2)
pencat=replace(pencat,"H_ulr1",pname1)
pencat=replace(pencat,"H_ulr2",pname2)
elseif n<>0 and i>0 and n-i=0 then
pencat=replace(pencat,"H_pages",page3)
pencat=replace(pencat,"H_ulr2",pname2)
end if
pencat=replace(pencat,"H_num",H_num)
pencat=replace(pencat,"H_first",H_first)
pencat=replace(pencat,"H_end",H_end)

pencat=replace(pencat,"labout",about)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(server.mappath(filePath& "\" & pname))
fout.WriteLine pencat
fout.close

set rs=server.createobject("adodb.recordset")
sql="select * from article where (newsid is null)"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("path")=filepath
rs("content")=content
rs("Nfrom")=from
rs("selectpic")=selectpic
rs("typeid")=typeid
rs("typename")=typename1
rs("tjnews")=tjnews
rs("shenghe")=shenghe
rs("N_Fname")=fname
rs("zznews")=zznews
rs("about")=about
rs.update

articleid=rs("newsid")
rs1.close
set rs1=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
next
alwaysfirst
2008-06-20 · TA获得超过491个赞
知道小有建树答主
回答量:457
采纳率:0%
帮助的人:227万
展开全部
其实就是制作一个模板页,将需要显示的地方已标记代替
然后生成静态页面时调用这个模板,将标记替换成显示的内容,使用FSO输出保存到服务器,将输出路径保存到数据库
例:
模板页 保存到数据库中,其中{$Menu$},{$Body$}是要替换的标记
-----------------------------------------------------
<html>
<head>
<title>首页</title>
</head>
<body>
菜单{$Menu$}<Br>
内容{$Body$}
</body>
</html>
------------------------------------------------------------

'生成页面
<%'打开模板代码,并将其中特殊代码转变为接受值
sql1="select m_id,m_html from c_moban where m_id=1"
set rs1=Server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
mb_code=rs1("m_html") '刚才保存的模板代码
rs1.close
set rs1=nothing

'读取替换标记
sql2="select id,menu,body from c_neirong where m_id=1" 'm_id=1为首页
set rs=Server.CreateObject("adodb.recordset")
rs.open sql2,conn,1,1

'批量使用循环,加入下面这句do while
do while not rs.eof

menu=rs("menu")
body=rs("body")
idhtml=rs("id")
'替换标记
mb_code=replace(mb_code,"{$Menu$}",menu)
mb_code=replace(mb_code,"{$Body$}",body)

%>

<%'生成HTML页面
'批量的名称,已ID命名,达到没有重名的目的
'filepath=idhtml &".html"
filepath="index.html"
Set fout = fso.CreateTextFile(Server.MapPath(filepath))
fout.WriteLine mb_code
fout.close
response.write "生成首页静态页面成功"

'这里做一个记录生成页面的地址的保存
conn.execute "insert into url_dz(fenlei,url) values('分类名称',fielpath)

rs.movenext
loop
'关闭连接
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

如果是批量的,只要加个循环就可以了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式