ASP生成静态页面的方法(4)

作者:佚名 时间:2010-05-27 12:13:00 


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)
%>
<%'生成HTML页面
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(c_filepath))
fout.WriteLine mb_code
fout.close
%>
<%response.redirect("showit.asp")%>
<%end if%>
<%
if id<>"" then
Set rs = Server.CreateObject ("ADODB.Recordset")
sql="select * from c_news where c_id="&id
rs.Open sql,conn,1,1
c_id=rs("c_id")
c_filepath=rs("c_filepath")
c_title=rs("c_title")
c_content=rs("c_content")
end if
%>
<form action="change.asp" method="post">
Title:<input type="text" name="c_title" value=<%=c_title%>><br>
Content:<br>
<textarea name="c_content" rows="8" cols="30"><%=c_content%></textarea><br>
<input type="submit" value="change" name="submit">
<input type="reset" value="Reset">
<input name="c_id" type="hidden" value="<%=id%>">
<input name="c_filepath" type="hidden" value="<%=c_filepath%>">
</form>


8,删除记录页del.asp
同样!删除,除了删除数据库表中的记录,与其对应的HTML页面也需删除。代码如下:

引用:

<!--#include file="conn.asp" -->
<%
c_id = request.querystring("c_id")
sql = "Select * from c_news where c_id="&c_id
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open sql,conn,2,3
filepath=rs("c_filepath")
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(Server.mappath(filepath))
Set fso = nothing
rs.delete
rs.close
Set rs = Nothing
conn.close
set conn=nothing
%>
<%response.redirect("showit.asp")%>


四,其它功能
模板管理页面:
不会每次都是打开数据库表进行增加或者修改模板代码吧,所以,管理代码的页面程序不能少了,自己捣鼓下应该很简单的。当然,之前管理员的登录认证程序就不在书中交代了:)还有,如果设计了多个模板,那么在发表信息的时候应添加模板选择单选框,同样在执行转换HTML时,SQL选择的不同m_id了。

标签:模板,静态,asp
0
投稿

猜你喜欢

  • Sql Server 查询性能优化之走出索引的误区分析

    2012-05-22 18:56:52
  • SQLServer与服务器连接时出错的解决方案

    2009-06-28 14:35:00
  • XML轻松学习手册(3)XML的术语

    2008-09-05 17:17:00
  • SQL Server数据库连接查询的种类及其应用

    2009-01-06 11:28:00
  • PJBlog3优化——301定向跳转解决重复内容的问题

    2009-05-20 10:40:00
  • 对架构师的建议:博学笃志,切问近思

    2009-09-25 12:55:00
  • 解读HTML:大厦的基石

    2008-12-01 12:57:00
  • 如何正确处理ajax 302跳转问题回博客首页

    2009-02-28 14:01:00
  • asp无组件备份与还原数据库

    2007-09-24 13:19:00
  • 如何从Notes中读取数据?

    2009-11-15 19:57:00
  • asp网上购物车实例代码

    2007-10-03 13:43:00
  • 对“打造自己的reset.css”文中观点的不同看法

    2009-03-08 18:05:00
  • Dreamweaver4探谜系列(1)

    2010-09-05 21:12:00
  • em和strong的区别

    2008-12-23 12:08:00
  • 较完善的日历组件js源码(兼容)

    2010-08-08 08:43:00
  • Dreamweaver制作网页11种技巧详解

    2007-11-05 14:00:00
  • 用CSS实现柱状图(Bar Graph)的方法(四)—table实现复杂柱状图

    2008-05-28 12:55:00
  • 用javascript给表格加滚动条

    2008-10-15 10:03:00
  • ORACLE数据库事务隔离级别介绍

    2012-10-07 10:43:36
  • asp如何制作一个小巧的购物车?

    2010-07-07 12:25:00
  • asp之家 网络编程 m.aspxhome.com