'jsp에서 include'에 해당되는 글 1건

  1. 2007/09/17 JSP에서 다른 파일 include 하는 2가지 방법
2007/09/17 20:15

JSP의 include 기능

JSP에는 현재의 JSP파일에 다른 파일(HTML 이나 JSP 등)을 포함시키기 위해 두가지 방법을 제공합니다.

1. include directive(지시어)
2. include action(액션)

[두 방식의 비교]

공통점은 둘다 다른 파일을 불러온다는 점에서 유사합니다.
차이점은 include 지시어는 해당파일의 소스내용을 포함시킨다음 컴파일하지만,
include 액션은 실행시점에서 해당파일을 수행하여 그 결과를 포함시킵니다.

[사용방법]

1. include 지시어
<%@ include file="includedfile.jsp" %>

2. include 액션
<jsp:include page="includedfile.jsp" />

include action은 파라미터를 전달할 수 있는 기능도 제공합니다.

[Example]

---------------------------------------------------
파일명 : include_action.jsp 의 일부
---------------------------------------------------
<jsp:include page="footer2.jsp">
 <jsp:param name="email" value="
include_action@kimgisa.net" />
 <jsp:param name="tel" value="010-3333-1234" />
</jsp:include>


---------------------------------------------------
파일명 : footer2.jsp (인클루드 되는 파일) 의 일부
---------------------------------------------------
E-mail : <%= request.getParameter("email") %>
Tel NO : <%= request.getParameter("tel") %>


---------------------------------------------------

include_action.jsp 수행결과
---------------------------------------------------
E-mail : include_action@kimgisa.net
Tel NO :  : 010-3333-1234

Posted by kimgisa.net