ASP生成靜態頁小例子

2021-04-18 10:49:33 字數 3606 閱讀 3059

先是index.asp檔案當然也可以用html的檔案

然後是send.asp這個就是生成靜態頁的檔案

<%

function chan_time(shijian)'轉換日期時間函式

s_year=year(shijian)

if len(s_year)=2 then s_year="20"&s_year

s_month=month(shijian)

if s_month<10 then s_month="0"&s_month

s_day=day(shijian)

if s_day<10 then s_day="0"&s_day

s_hour=hour(shijian)

if s_hour<10 then s_hour="0"&s_hour

s_minute=minute(shijian)

if s_minute<10 then s_minute="0"&s_minute

chan_time=s_year & s_month & s_day & s_hour & s_minute

end function

function chan_data(shijian) '轉換日期時間函式

s_year=year(shijian)

if len(s_year)=2 then s_year="20"&s_year

s_month=month(shijian)

if s_month<10 then s_month="0"&s_month

s_day=day(shijian)

if s_day<10 then s_day="0"&s_day

chan_data=s_year & s_month & s_day

end function

function chan_file(shijian)'轉換日期時間函式

s_month=month(shijian)

if s_month<10 then s_month="0"&s_month

s_day=day(shijian)

if s_day<10 then s_day="0"&s_day

s_hour=hour(shijian)

if s_hour<10 then s_hour="0"&s_hour

s_minute=minute(shijian)

if s_minute<10 then s_minute="0"&s_minute

s_ss=second(shijian)

if s_ss<10 then s_ss="0"&s_ss

chan_file = s_month & s_day & s_hour & s_minute & s_ss

end function

top=""

botom="

"msg=request.form("msg")

msg=replace(msg,vbcrlf,"")

msg=replace(msg,chr(9),"")

msg=replace(msg," "," ")

msg=replace(msg,"/r/n","

")msg=replace(msg,"/n","

")msg=top&msg&botom

set fs=server.createobject("scripting.filesystemobject")

if (fs.folderexists(all_tree2)) then'判斷今天的資料夾是否存在

else

fs.createfolder(all_tree2)

end if

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

set ts = fs.createtextfile(filez,true) '寫檔案

for z=1 to len(msg)

write_now=mid(msg,z,1)

ts.write(write_now)

next

' ts.writeline(all_msg)

ts.close

set ts=nothing '檔案生成

if err.number<>0 or err then%><%else%><%end if

set myfile = fs.getfile(filez)

if (fs.folderexists(all_tree2)) then

else

fs.createfolder(all_tree2)

end if

myfile.name= left(myfile.name,len(myfile.name)-4)&".htm"

set myfile=nothing

set fs=nothing

set fdir=nothing

function get_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,"___fckpd___2quot;,"")

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

end function

%>

最後在目錄下加個news資料夾,測試就搞掂了!!

ASP生成靜態頁(收1)

下面的例子是將 index.asp?id 1 index.asp?id 2 index.asp?id 3 這三個動態頁面,分別生成ndex1.htm,index2.htm,index3.htm存在根目錄下面 function asp2html filename dim code code repla...

asp 靜態生成

asp 靜態生成 filename test.htm if request body then setfso server.createobject scripting.filesystemobject sethtmlwrite filename htmlwrite.write htmlwrite....

生成靜態頁

先定義乙個staticfilecachemodule 實現ihttpmodule介面 定製beginrequest事件 再定義乙個類 要生成靜態頁面的繼承它就行了 將頁面內容輸出到瀏覽器 response.write pagecontent 當然不要忘在配置web.confing 用模板生成靜態頁 ...