ASP生成静态页之添加新闻(3)-将以下文件保存为:addnews.asp !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 T...

海南网站建设,网页设计
记忆工作中的点滴
首页>> Asp技术 >>ASP生成静态页之添加新闻(3)

将以下文件保存为:addnews.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>
<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 id="form1" name="form1" method="post" action="savenews.asp">
  <tr>
    <td class="title" width="100">标题:</td>
    <td><input name="title" type="text" id="title" />
    </td>
  </tr>
  <tr>
    <td class="title">内容:</td>
    <td><textarea name="content" cols="70" rows="5" id="content"></textarea></td>
  </tr>
  <tr>
    <td class="title">&nbsp;</td>
    <td><input type="submit" name="Submit" value="提交" /> 
      <input type="reset" name="Submit2" value="重置" /></td>
  </tr>
  </form>
</table>
</body>
</html>

 

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

<%'容错处理
On Error Resume Next
%>

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

<%'接受传递值
title=request.form("title")
content=request.form("content")
'生成HTML文件名,建立文件夹,指定文件路径
fname = makefilename(now()) 'makefilename为自定义函数
folder = "html/"&date()&"/"
filepath = folder&fname
'将接受值及路径保持至数据库表
sql = "Select * from News"
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open sql,conn,1,3
rs.addnew
rs("title")=title
rs("content")=content
rs("filepath")=filepath
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")
fso.CreateFolder(Server.MapPath(folder))
Set fout = fso.CreateTextFile(Server.MapPath(filepath))
fout.WriteLine mb_code
fout.close
%>
<SCRIPT LANGUAGE="JScript">
var truthBeTold = window.confirm("新闻添加成功!\n是否继续添加?");
if (truthBeTold) {
window.location = ("addnews.asp");
}  else  window.location = ("adminnews.asp");
</SCRIPT>


×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

打赏作者
版权所有,转载注意明处:不懂戀愛魚兒 » ASP生成静态页之添加新闻(3)
标签: asp 静态

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)