zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

在ASP中使用FSO组件生成HTML页面

ASP组件HTML 使用 生成 页面 FSO
2023-06-13 09:13:46 时间
"共有两个页面index.htm是首页.程序比较简单,主要是用了ASP里的文件操作对象。
<!--index.htm------------------------------------------------------------------------------->

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>

<body>
<tablewidth="770"border="0"align="center"cellpadding="0"cellspacing="0">
<tr>
<td><formname="form1"method="post"action="send.asp">
<tablewidth="100%"border="0"cellpadding="0"cellspacing="0"bgcolor="#CCFFFF">
<tr>
<tdheight="20"><divalign="center">发送消息</div></td>
</tr>
<tr>
<td><divalign="center">
<textareaname="msg"cols="100"rows="6"></textarea>
</div></td>
</tr>
<tr>
<td><divalign="center">
<inputtype="submit"name="Submit"value="Submit">
<inputtype="reset"name="Submit2"value="Reset">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
"//send.asp

<%
functionchan_time(shijian)"转换日期时间函数
s_year=year(shijian)
iflen(s_year)=2thens_year="20"&s_year
s_month=month(shijian)
ifs_month<10thens_month="0"&s_month
s_day=day(shijian)
ifs_day<10thens_day="0"&s_day
s_hour=hour(shijian)
ifs_hour<10thens_hour="0"&s_hour
s_minute=minute(shijian)
ifs_minute<10thens_minute="0"&s_minute
chan_time=s_year&s_month&s_day&s_hour&s_minute
endfunction

functionchan_data(shijian)"转换日期时间函数
s_year=year(shijian)
iflen(s_year)=2thens_year="20"&s_year
s_month=month(shijian)
ifs_month<10thens_month="0"&s_month
s_day=day(shijian)
ifs_day<10thens_day="0"&s_day
chan_data=s_year&s_month&s_day
endfunction

functionchan_file(shijian)"转换日期时间函数
s_month=month(shijian)
ifs_month<10thens_month="0"&s_month
s_day=day(shijian)
ifs_day<10thens_day="0"&s_day
s_hour=hour(shijian)
ifs_hour<10thens_hour="0"&s_hour
s_minute=minute(shijian)
ifs_minute<10thens_minute="0"&s_minute
s_ss=second(shijian)
ifs_ss<10thens_ss="0"&s_ss
chan_file=s_month&s_day&s_hour&s_minute&s_ss
endfunction
top="<html><head><title>news</title></head><body>"
botom="</body></html>"
msg=request.Form("msg")
msg=replace(msg,vbcrlf,"")
msg=replace(msg,chr(9),"")
msg=replace(msg,""," ")
msg=replace(msg,"\r\n","<br>")
msg=replace(msg,"\n","<br>")
msg=top&msg&botom
Setfs=Server.CreateObject("Scripting.FileSystemObject")
all_tree2=server.mappath("news")&"\"&chan_data(now)
if(fs.FolderExists(all_tree2))then"判断今天的文件夹是否存在
else
fs.CreateFolder(all_tree2)
endif
pass=chan_file(now)
randomize"使用系统计时器来初始化乱数产生器
pass=rnd(pass)
pass=get_pass(pass)
pass=left(pass,10)

file1=pass
files=file1&".txt"
filez=all_tree2&"\"&files

setts=fs.createtextfile(filez,true)"写文件
forz=1tolen(msg)
write_now=mid(msg,z,1)
ts.write(write_now)
next
"ts.writeline(all_msg)
ts.close
setts=nothing"文件生成

iferr.number<>0orerrthen%>
<scriptlanguage="javascript">
alert("不能完成")
</script>
<%else%>
<scriptlanguage="javascript">
alert("已完成")
history.back();
</script>
<%endif
SetMyFile=fs.GetFile(filez)
all_tree2=server.mappath("news")&"\"&chan_data(now)
if(fs.FolderExists(all_tree2))then
else
fs.CreateFolder(all_tree2)
endif
MyFile.name=left(MyFile.name,len(MyFile.name)-4)&".htm"
setMyFile=nothing
setfs=nothing
setfdir=nothing
functionget_pass(pass)

pass=cstr(pass)
pass=replace(pass,"","")
pass=replace(pass,"","")
pass=replace(pass,"-","")
pass=replace(pass,"","")
pass=replace(pass,":","")
pass=replace(pass,".","")
pass=replace(pass,"+","")
pass=replace(pass,"_","")
pass=replace(pass,"<","")
pass=replace(pass,">","")
pass=replace(pass,"!","")
pass=replace(pass,"@","")
pass=replace(pass,"#","")
pass=replace(pass,"$","")
pass=replace(pass,"%","")
pass=replace(pass,"^","")
pass=replace(pass,"&","")
pass=replace(pass,"*","")
pass=replace(pass,"(","")
pass=replace(pass,")","")
pass=replace(pass,"=","")
pass=replace(pass,"\","")
pass=replace(pass,"/","")
pass=replace(pass,"|","")
get_pass=pass

endfunction

%>


"//

把send.asp和index.htm放到你的ASP目录下,然后再建一个news文件夹。打开浏览器,在地址栏里输入:http://你的机器名/你的ASP虚拟目录名/index.html输入文字,然后提交,OK!看看你的ASP目录里新建的news文件夹里是不是多了个新的文件夹,而且是以当前日期命名的。里面有你刚刚提交的文字,看看是不是生成了HTML文件。怎么样,你可以在此基础上做个简单的新闻发布系统。