ASP生成静态页(5)

将以下文件保存为:del.asp

<!--#include file="conn.asp" -->

<%
id = request.querystring("id")
sql = "Select * from news where id="&id
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open sql,conn,2,3

filepath=rs("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.write "<script>alert('成功删除指定的文件!');window.location.href='adminnews.asp';</script>"

%>

 

将以下文件保存为:edit.asp

<!--#include file="conn.asp" -->
<!--#include file="lib.asp" -->
<%id=request.querystring("id")%>
<%
if request.form("submit")="提交" then
title=request.form("title")
content=request.form("content")
id=request.form("id")
filepath=request.form("filepath")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from news where id="&id
rs.Open sql,conn,1,3
rs("title")=title
rs("content")=content
rs("time")=now()
rs.update
rs.close
Set rs = Nothing
%>
<%'打开模板代码,并将其中特殊代码转变为接受值
sql1="select id,moban from Template where id=1"
set rs1=Server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
mb_code=rs1("moban")
rs1.close
set rs1=nothing
conn.close
set conn=nothing
title=htmlencode(title)
content=htmlencode(content)
mb_code=replace(mb_code,"$time$",now())
mb_code=replace(mb_code,"$title$",title)
mb_code=replace(mb_code,"$content$",content)
%>
<%'生成HTML页面
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(Server.MapPath(filepath))
fout.WriteLine mb_code
fout.close
%>
<%Response.Write "<script>alert('成功修改指定新闻!');window.location.href='adminnews.asp';</script>" %>
<%end if%>
<%
if id<>"" then
Set rs = Server.CreateObject ("ADODB.Recordset")
sql="select * from news where id="&id
rs.Open sql,conn,1,1
id=rs("id")
filepath=rs("filepath")
title=rs("title")
content=rs("content")
end if
%>
<!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>edit</title>
<style type="text/css">
<!--
body {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 font-weight: normal;
 color: #000000;
 margin:0px auto;
 line-height:25px;
}
.table {
    margin-top:80px;
 border:1px #e6e6e6 solid;
}
.title {
    line-height:30px;
 text-align:right;
 font-size:16px;
 background:#FAFAFA;
}
-->
</style>

</head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
<form action="edit.asp" method="post">
  <tr>
    <td class="title" width="100">标题:</td>
    <td><input name="title" type="text" id="title" value="<%=title%>" />
    </td>
  </tr>
  <tr>
    <td class="title">内容:</td>
    <td><textarea name="content" cols="70" rows="5" id="content"><%=content%></textarea></td>
  </tr>
  <tr>
    <td class="title">&nbsp;</td>
    <td><input type="submit" name="Submit" value="提交" /> 
      <input type="reset" name="Submit2" value="重置" />
   <input name="id" type="hidden" value="<%=id%>">
<input name="filepath" type="hidden" value="<%=filepath%>"></td>
  </tr>
  </form>
</table>
</body>
</html>

 

引用地址:

post by 不懂戀愛魚兒 | 2009年12月29日 | 归档于 [Asp技术]
标签: asp 静态

发表评论

sitemap