728x90

Directive 문법 <%@ include file="파일 위치" %> 와

Action Tag <jsp:include page="파일위치" /> 의 차이점



예> main.jsp  sub_1.jsp  sub2.jsp 가 있다고 가정

Directive 문법을 이용한 include 는 main.jsp 에 sub1.jsp sub2.jsp 이 함께 합쳐져서 컴파일되므로 중복된 변수를 쓸수없다.


하지만


Action Tag 문법을 이용한 include는 모든페이지가 따로 컴파일되고 메인에서 필요할때마다 가져다 쓰는것이기때문에 중복된 변수 사용이 가능하다.




    main.jsp
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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
    int i;
    i = 10;
%>
 
<!-- Directive 문법을 통한 include -->
<%@ include file="../includes/header.jsp" %>
 
<hr/>
<h1>include 액션태그 예제1</h1>
이 페이지는 액션태그를 이용한 인클루드를 사용하고 있습니다.
<hr/>
 
<!-- Action Tag를 통한 include -->
<jsp:include page="../includes/footer.jsp"/>
 
</body>
</html>





  header.jsp
1
2
3
4
5
6
7
8
9
10
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<h2>여기는 헤더의 내용입니다.</h2>
<b>작성 : 홍길동</b>
<br/>
 
<!-- 만약 i변수를 새로 주면 에러가 남 main.jsp에서 header.jsp를 
    Directive 문법으로 include 했기때문 -->
<!-- i를 출력 -->
i = <%=i%>



    footer.jsp
1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<h2>여기는 푸터의 내용입니다.</h2>
<div align="right">&copy;Copyright reserved</div>
 
<!-- main.jsp 에서 footer.jsp를 Action Tag로 include 를 했기때문에 
    같은 i변수로 지정이 가능하다 -->
<%
    int i;
    i= 20;
%>
i = <%= i %>



Posted by 앗뜨거
,