建站代码网

热门标签

asp生成html

目前数据库的设计需要两个表:一个是存放模板数据的;一个是存放信息内容的。
 

1,建立新数据库asp2html.mdb

2,设计新数据库表c_moban
字段m_id(自动编号,主关键字);字段m_html(备注类型)。
并将下列完整的代码拷贝至m_html字段


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=hz">
<title>Cnbruce.Com | ASP2HTML TEST</title>
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="5" cellspacing="2">
  <tr align="right" bgcolor="#CCCCCC"> 
    <td height="20" colspan="2">$cntop$</td>
  </tr>
  <tr valign="top"> 
    <td width="25%" bgcolor="#e5e5e5">$cnleft$</td>
    <td width="74%" bgcolor="#f3f3f3">$cnright$</td>
  </tr>
</table>
</body>
</html>

3,设计新数据库表c_news

字段c_id:自动编号,主关键字
字段c_title:文本类型,保存文章标题
字段c_content:备注类型,保存文章内容
字段c_filepath:文本类型,保持生成文件的路径地址
字段c_time:日期/时间类型,默认值:Now()

 创建newsfile ,存放生成网页的地方

下面我们正式开始,作品代码如下:

conn.asp ***************************************** index.asp <%@LANGUAGE="VBscript" CODEPAGE="936"%> <!--#include file="conn.asp" --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <% sql1="select * from c_news" set rs1=Server.CreateObject("adodb.recordset") rs1.open sql1,conn,1,1 do while not rs1.eof %> <table width="300" border="0" cellspacing="0" cellpadding="0"> <tr> <td><%=rs1("c_id")%></td> <td><a href="<%=rs1("c_filepath")%>"><%=rs1("c_title")%></a></td> <td><a href="del.asp?c_id=<%=rs1("c_id")%>">删除</a></td> <td><a href="chang.asp?c_id=<%=rs1("c_id")%>">修改</a></td> </tr> </table> <p> <% rs1.movenext loop rs1.close set rs1=nothing %> </p> <p>添加 a<a href="add.asp">dd.asp</a> </p> </body> </html> *************************** lib.asp

<%
'生成文件名的函数
function makefilename(fname)
fname = fname
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 & ".shtml"
end function

'保持数据格式不变的函数
function HTMLEncode(fString)
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "<br>")
fString = Replace(fString, CHR(10), "<br>")
HTMLEncode = fString
end function
%>


**********************

del.asp

<!--#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("index.asp")%>

*************************************************

add.asp

<%@LANGUAGE="VBscript" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form action="addit.asp" method="post">
Title:<input type="text" name="c_title"><br>
Content:<br>
<textarea name="c_content" rows="8" cols="30"></textarea><br>
<input type="submit" value="Add">
<input type="reset" value="Reset">

X