ASP 포함 파일


#include 지시문

#include 지시문을 사용하여 서버가 실행하기 전에 한 ASP 파일의 내용을 다른 ASP 파일에 삽입할 수 있습니다.

#include 지시문은 여러 페이지에서 재사용될 함수, 머리글, 바닥글 또는 요소를 만드는 데 사용됩니다.


#include 지시문을 사용하는 방법

다음은 "mypage.asp"라는 파일입니다.

<!DOCTYPE html>
<html>
<body>
<h3>Words of Wisdom:</h3>
<p><!--#include file="wisdom.inc"--></p>
<h3>The time is:</h3>
<p><!--#include file="time.inc"--></p>
</body>
</html>

다음은 "wisdom.inc" 파일입니다.

"One should never increase, beyond what is necessary,
the number of entities required to explain anything."

다음은 "time.inc" 파일입니다.

<%
Response.Write(Time)
%>

브라우저에서 소스 코드를 보면 다음과 같이 보일 것입니다.

<!DOCTYPE html>
<html>
<body>
<h3>Words of Wisdom:</h3>
<p>"One should never increase, beyond what is necessary,
the number of entities required to explain anything."</p>
<h3>The time is:</h3>
<p>11:33:42 AM</p>
</body>
</html>


파일 포함 구문

ASP 페이지에 파일을 포함하려면 주석 태그 안에 #include 지시문을 넣으십시오.

<!--#include virtual="somefilename"-->

or

<!--#include file ="somefilename"-->

가상 키워드

virtual 키워드를 사용하여 가상 디렉터리로 시작하는 경로를 나타냅니다.

"header.inc"라는 파일이 /html이라는 가상 디렉터리에 있는 경우 다음 줄은 "header.inc"의 내용을 삽입합니다.

<!-- #include virtual ="/html/header.inc" -->

파일 키워드

상대 경로를 나타내려면 file 키워드를 사용하십시오. 상대 경로는 포함 파일이 포함된 디렉토리로 시작합니다.

html 디렉토리에 파일이 있고 "header.inc" 파일이 html\headers에 있는 경우 다음 줄은 파일에 "header.inc"를 삽입합니다.

<!-- #include file ="headers\header.inc" -->

포함된 파일의 경로(headers\header.inc)는 포함된 파일에 상대적입니다. 이 #include 문이 포함된 파일이 html 디렉토리에 없으면 문이 작동하지 않습니다.


팁 및 참고 사항

위의 섹션에서는 포함된 파일에 대해 파일 확장자 ".inc"를 사용했습니다. 사용자가 INC 파일을 직접 탐색하려고 하면 해당 내용이 표시됩니다. 포함된 파일에 기밀 정보나 사용자에게 보여주고 싶지 않은 정보가 포함되어 있으면 ASP 확장자를 사용하는 것이 좋습니다. ASP 파일의 소스 코드는 해석 후에 표시되지 않습니다. 포함된 파일에는 다른 파일도 포함될 수 있으며 하나의 ASP 파일에는 동일한 파일이 두 번 이상 포함될 수 있습니다.

중요: 포함된 파일은 스크립트가 실행되기 전에 처리되고 삽입됩니다. 다음 스크립트는 ASP가 변수에 값을 할당하기 전에 #include 지시문을 실행하기 때문에 작동하지 않습니다.

<%
fname="header.inc"
%>
<!--#include file="<%fname%>"-->

INC 파일에서 스크립트 구분 기호를 열거나 닫을 수 없습니다. 다음 스크립트는 작동하지 않습니다.

<%
For i = 1 To n
  <!--#include file="count.inc"-->
Next
%>

그러나 이 스크립트는 다음과 같이 작동합니다.

<% For i = 1 to n %>
  <!--#include file="count.inc" -->
<% Next %>