이 기사는 ASP가 HTML을 생성하는 몇 가지 방법을 알려줍니다. 필요한 친구는 아래 내용의 세부 사항을 참조 할 수 있습니다.
방법 1 : FSO
set fs = createobject ( "scripting.filesystemobject")
newFile = server.mappath ( "/asp/chap06/at/newfile.html")
'새 파일 생성/newfile.html, 파일이 이미 존재하면 덮어 쓰기
set a = fs.creatextfile (NewFile, True)
응답. "새 파일이 생성되었습니다!"
A. 클로즈
file = server.mappath ( "newfile.html")
set txt = fs.opentextfile (file, 8, true) '끝에 데이터를 쓸 수있는 파일에 열려
data1 = "이 문장은 Writeline 메소드를 사용하여 작성됩니다! ~~"
txt.writeline data1
data2 = "이 문장은 쓰기 메소드를 사용하여 작성됩니다! ~~"
txt.write data2
txt.close
방법 2 : XMLHTTP
set xml = server.createobject ( "microsoft.xmlhttp")
'다음 주소를 홈페이지의 파일 주소로 바꾸십시오. http : //로 시작하여 절대 경로를 사용하면 상대 경로를 작성할 수 없습니다.
xml.open "get", "http://www.phpup.com", false
xml.send
BodyText = XML.ResponseBody
bodytext = bytestobstr (bodytext, "gb2312")
xml = 아무것도 설정하지 않습니다
희미한 fso, myfile
set fso = createobject ( "scripting.filesystemobject")
set myfile = fso.creatextfile (server.mappath ( "aa.htm"), true)
myfile.writeline (bodytext)
myfile.close
다른:
1
다음 예제는 세 가지 역학입니다 : index.asp? id = 1/index.asp? id = 2/index.asp? id = 3/
이 페이지는 ndex1.htm, index2.htm, index3.htm을 각각 생성하며 루트 디렉토리에 있습니다.
dim strurl, item_classid, id, filename, filepath, do_url, html_temp
html_temp = "
i = 1 ~ 3의 경우
html_temp = html_temp & "
item_classid = i
filename = "index"& item_classid & ". htm"
filepath = server.mappath ( "/") & "/"& filename html_temp = html_temp & filepath & "
do_url = "http : //"
do_url = do_url & request.servervariables ( "server_name") & "/main/index.asp"
do_url = do_url & "? item_classid ="& item_classid
strurl = do_url
Dim objxmlhttp
set objxmlhttp = server.createobject ( "microsoft.xmlhttp")
objxmlhttp.open "get", strurl, false
objxmlhttp.send ()
희미한 binfiledata
binfiledata = objxmlhttp.responsebody
희미한 objadostream
set objadostream = server.createObject ( "adodb.stream")
objadostream.type = 1
objadostream.open ()
objadostream.write (binfiledata)
objadostream.savetofile FilePath, 2
objadostream.close ()
다음
html_temp = html_temp & "
%>
response.write ( "성공적으로 생성 된 파일 :")
response.write ( "
")
응답. html_temp
%>
기능 bytestobstr (body, cset)
희미한 objstream
set objstream = server.createobject ( "adodb.stream")
objstream.type = 1
objstream.mode = 3
objstream.open
objstream.write body
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
objstream = 아무것도 설정하지 않습니다
엔드 기능
%>
2
public templatefile, tmpdata
sub ofile () '파일을 열고 파일 내용을 tmpdata에 넣습니다.
다음에 오류가 재개됩니다
tmpdata = ""
set asstream = server.createobject ( "adodb.stream")
asstream.type = 2'File 유형 텍스트
asstream.mode = 3 '읽기 및 쓰기
asstream.open
asstream.charset = "gb2312" '문자 세트
asstream.loadfromfile (tempelatefile) '파일에서로드
ASSP = Astream.Size
err.number0 인 경우
xz = -18
응답. TemplateFile & "쓰기
"
err.clear
tmpdata = ""
또 다른
tmpdata = astream.readtext (Assp)
끝 If
종료 서브
Sub Save_File ()
Ofile ()
recfilen = server.mappath (dts)
asstream.flush
asstream.close
asstream.type = 2
asstream.mode = 3
asstream.open
asstream.charset = "gb2312"
asstream.position = 0
asstream.writetext tmpdata, 1 '쓰기 스트리밍
Asstream.savetofile recfilen, 2 's ~ 파일
종료 서브
함수 dts () '랜덤 파일 이름을 생성합니다
LEN (Month (now))> 1 인 경우
mm = Month (now ())
또 다른
mm = "0"& month (now ())
끝 If
Len (day (now (now ())> 1 인 경우
d = day (now ())
또 다른
d = "0"& day (지금 ())
끝 If
LEN (Hour (지금 ())> 1 인 경우
h = 시간 (지금 ())
또 다른
h = "0"& Hour (지금 ())
끝 If
LEN (minute (now))> 1 인 경우
m = minute (now ())
또 다른
m = "0"& minute (now ())
끝 If
LEN (두 번째 (지금 (지금))> 1 인 경우
s = second (now ())
또 다른
s = "0"& second (now ())
끝 If
무작위 화
어퍼 바운드 = 9999
Lowerbound = 1000
rds = int ((어퍼 바운드 - 하단 바운드 + 1) * rnd + 하단 바운드)
DTS = "HTM/"& YEAR (NOW ()) & MM & D & H & M & S & RDS & ". HTM"
엔드 기능
title = request.form ( "title")
content = request.form ( "content")
tmpdata = replace (tmpdata, "
tmpdata = replace (tmpdata, "
templatefile = server.mappath ( "tempelate/1.htm") '템플릿 파일
save_file ()
%>
위는 ASP에 의해 HTML을 생성하는 몇 가지 방법입니다. 나는 당신이 그것에 대해 배웠다고 믿습니다. 더 많은 관련 컨텐츠는 Wuxin Technology Channel에 계속주의를 기울이십시오.