ASP生成静态页面
6,显示数据库表记录,并做指向HTML页的链接:showit.asp
引用:
------------------------------
<!--#include file="conn.asp" -->
<!--#include file="lib.asp" -->
<%
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from c_news order by c_id desc"
rs.Open sql,conn,1,1
%>
<%
if rs.EOF and rs.BOF then
response.write ("暂时还没有文章,<a href=add.html>添加</a>")
else
Do Until rs.EOF
%>
<table width="758" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#000000">
<tr>
<td width="159" align="right" bordercolor="#CCCCCC" bgcolor="#CCCCCC"><%=rs("c_time")%></td>
<td width="591" bordercolor="#f3f3f3" bgcolor="#f3f3f3"><a href=<%=rs("c_filepath")%> target="a_blank"><%=rs("c_title")%></a></td>
</tr>
<tr>
<td valign="top" align="right" bordercolor="#ececec" bgcolor="#ececec">[<a href=del.asp?c_id=<%=rs("c_id")%>>Dell</a>][<a href=change.asp?c_id=<%=rs("c_id")%>>Edit</a>][<a href="add.html">Add</a>]</td>
<td valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><%=htmlencode(rs("c_content"))%></td>
</tr>
</table><br>
<%
rs.MoveNext
Loop
end if
%>
<%
rs.close
Set rs = Nothing
conn.close
set conn=Nothing
%>
------------------------------
7,修改数据内容页change.asp
修改数据内容,同时也需要修改更新对应的HTML页面。修改其实就是重新生成文件,且文件名和之前一样,类似文件的覆盖。
引用:
------------------------------
<!--#include file="conn.asp" -->
<!--#include file="lib.asp" -->
<%id=request.querystring("c_id")%>
<%
if request.form("submit")="change" then
c_title=request.form("c_title")
c_content=request.form("c_content")
c_id=request.form("c_id")
c_filepath=request.form("c_filepath")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from c_news where c_id="&c_id
rs.Open sql,conn,3,2
rs("c_title")=c_title
rs("c_content")=c_content
rs("c_time")=now()
rs.update
rs.close
Set rs = Nothing
%>
<%'打开模板代码,并将其中特殊代码转变为接受值
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
conn.close
set conn=nothing
c_title=htmlencode(c_title)
c_content=htmlencode(c_content)
mb_code=replace(mb_code,"$cntop{LogContent}quot;,now())
mb_code=replace(mb_code,"$cnleft{LogContent}quot;,c_title)
mb_code=replace(mb_code,"$cnright{LogContent}quot;,c_content)
%>