티스토리 뷰
asp 3.0 에서는
<!-- #include file="파일명" -->
<!-- #include virtual="파일명" -->
Server.Execute("파일명")
으로 다른 파일을 포함시켜 실행할 수 있다.
다른점은
위의 2개는 변수가 공유된다 하지만 파일명에 변수값을 줄 수 없다.
Server.Execute 는 변수가 공유되지 않는다 하지만 파일명을 변수값으로 줄 수 있다.
php 와 비교를 해보면 너무도 허접하고 불편한 언어가 asp 이다.
해결책은 없을까? 하면서도 찾지 못하다가 그나마 최선책을 찾아내었다.
Page1.asp :
Page2.asp :
출력 결과 :
Variable "strTest" on Page1= hello
We are in Page2 and have just modified Page1's "strTest" variable
We are back in Page1 and "strTest" is now= goodbye
<!-- #include file="파일명" -->
<!-- #include virtual="파일명" -->
Server.Execute("파일명")
으로 다른 파일을 포함시켜 실행할 수 있다.
다른점은
위의 2개는 변수가 공유된다 하지만 파일명에 변수값을 줄 수 없다.
Server.Execute 는 변수가 공유되지 않는다 하지만 파일명을 변수값으로 줄 수 있다.
php 와 비교를 해보면 너무도 허접하고 불편한 언어가 asp 이다.
해결책은 없을까? 하면서도 찾지 못하다가 그나마 최선책을 찾아내었다.
Page1.asp :
<% dim strTest : strTest = "hello" response.write "Variable ""strTest"" on Page1= " & strTest & "
" include("page2.asp") response.write "We are back in Page1 and ""strTest"" is now= " & strTest & "
" Function include(sFile) dim mfo, mf, sTemp, arTemp, arTemp2, lTemp, sTemp2, lTemp2, sFile2 If InStr(1,sFile,":") = 0 Then sFile = Server.MapPath(sFile) End If 'first read the file into a variable use FSO set mfo = Server.CreateObject("Scripting.FileSystemObject") 'does file exist? If mfo.FileExists(sFile) Then 'read it set mf = mfo.OpenTextFile(sFile, 1, false, -2) sTemp = mf.ReadAll mf.close set mfo = nothing Else sTemp = "" End If If sTemp <> "" Then 'sTemp contains the mixed ASP and HTML, so the next task is to dynamically replace the inline HTML with response.write statements arTemp = Split(sTemp,"<" & "%") sTemp = "" For lTemp = LBound(arTemp) to UBound(arTemp) If InStr(1,arTemp(lTemp),"%" & ">") > 0 Then 'inline asp arTemp2 = Split(arTemp(lTemp),"%" & ">") 'everything up to the % > is ASP code sTemp2 = trim(arTemp2(0)) If Left(sTemp2,1) = "=" Then 'need to replace with response.write sTemp2 = "Response.Write " & mid(sTemp2,2) End If sTemp = sTemp & sTemp2 & vbCrLf 'everything after the % > is HTML sTemp2 = arTemp2(1) Else 'inline html only sTemp2 = arTemp(lTemp) End If arTemp2 = Split(sTemp2,vbCrLf) For lTemp2 = LBound(arTemp2) to UBound(arTemp2) sTemp2 = Replace(arTemp2(lTemp2),"""","""""") 'replace quotes with doubled quotes sTemp2 = "Response.Write """ & sTemp2 & """" 'add response.write and quoting If lTemp2 < Ubound(arTemp2) Then sTemp2 = sTemp2 & " & vbCrLf" 'add cr+lf if not the last line inlined End If sTemp = sTemp & sTemp2 & vbCrLf 'add to running variable Next Next Execute sTemp ExecInclude = True End If End Function %>
Page2.asp :
<% strTest = "goodbye" response.write "We are in Page2 and have just modified Page1's ""strTest"" variable
" %>
출력 결과 :
Variable "strTest" on Page1= hello
We are in Page2 and have just modified Page1's "strTest" variable
We are back in Page1 and "strTest" is now= goodbye
다른 방법 :
SSDI 서버측 COM Object 이용
다른 방법 :
<% ' **** Dynamic ASP include v.2.2
' **** by TFI
' usage: include(filename)
Function fixInclude(content)
out=""
content = regreplace(content,"","<"&"%include(""$1"")%"&">",false)
'content = regreplace(content,"","
ERROR: 'include virtual' not supported!
",false)
content = replace(content,"<"&"%=","<"&"%response.write ")
content = replace(content,"<"&"% =","<"&"%response.write ")
'content = regreplace(content,"<"&"% *= *","<"&"%response.write ",false)
pos1 = instr(content,"<%")
pos2 = instr(content,"%"&">")
if pos1 > 0 then
before = mid(content,1,pos1-1)
before = replace(before,"""","""""")
before = replace(before,vbcrlf,""""& vbcrlf &"response.write vbcrlf&""")
before = vbcrlf &"response.write """& before &""""& vbcrlf
middle = mid(content,pos1+2,(pos2-pos1-2))
after = mid(content,pos2+2,len(content))
out = before & middle & fixInclude(after)
else
content = replace(content,"""","""""")
content = replace(content,vbcrlf,""""& vbcrlf &"response.write vbcrlf&""")
out = vbcrlf &"response.write """& content &""""
end if
fixInclude=out
end function
function regreplace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
dim objRegExp : set objRegExp = new RegExp
with objRegExp
.Pattern = strPattern
.IgnoreCase = varIgnoreCase
.Global = True
end with
regreplace = objRegExp.replace(strOriginalString, strReplacement)
set objRegExp = nothing
end function
Function getMappedFileAsString(byVal strFilename)
Dim fso,td
Set fso = Server.CreateObject("Scripting.FilesystemObject")
Set ts = fso.OpenTextFile(Server.MapPath(strFilename), 1)
getMappedFileAsString = ts.ReadAll
ts.close
Set ts = nothing
Set fso = Nothing
End Function
Function include(filename)
executeglobal(fixInclude(getMappedFileAsString(filename)))
End Function
%>'웹프로그래밍 > ASP Classic' 카테고리의 다른 글
| [Classic ASP] 네이버LAB 포토에디터 API 활용예제 (0) | 2010.11.23 |
|---|---|
| 문장에서 따옴표를 특수문자 따옴표로 변경해주기 (0) | 2010.11.22 |
| 네이버 오픈API 추천검색어 변환 파싱 (jQuery, ASP 사용) (2) | 2010.08.23 |
| ASP에서 Javascript 함수 쓰기 (0) | 2010.08.18 |
| 미니위니 에디터 For ASP EX2 (0) | 2010.08.09 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- mssql
- 한글
- Docker
- centos
- iis
- JQuery
- Android
- nodejs
- iphone
- javascript
- nginx
- Debug
- 워드프레스
- sencha touch
- CSS
- IOS
- IE
- Mac
- laravel
- Prototype
- classic asp
- JSON
- 안드로이드
- PHP
- Linux
- macos
- Wordpress
- ASP
- git
- API
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
글 보관함