web

[jsp] jsp 파일 불러오기 - include & action tag

소댓 2023. 4. 30. 14:45

 

< a.jsp파일을 불러오기 - include&action tag >

 

* include
  <%@ include file="a.jsp" %> 
  >> include 지시자를 사용하면 copy&paste 효과 

 

* jsp action tag 
  <jsp:include page="a.jsp"></jsp:include>
  >> 컴파일된 결과의 삽입

 


- [a.jsp]

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>a.jsp</title>
</head>
<body>
    <h3>푸른하늘 은하수</h3>
    
    <%
        int a = 10;
        out.println("a.jsp : "+a);
    %>
</body>
</html>
cs

 

 


- [b.jsp] : a.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
28
29
30
31
32
33
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <!-- a.jsp파일을 불러오기 -->
    <%-- <%@ include file="a.jsp" %> 
    jsp 주석은 브라우저에 기록도 xx--%>
    <!-- include 지시자를 사용하면 copy&paste 효과 -->
    
    <!-- jsp action tag -->
    <jsp:include page="a.jsp"></jsp:include>
    <!-- 컴파일된 결과의 삽입 -->
    <%
    // a 변수값을 출력
/*       out.println(a);   */
    
    
    %>
    
    <%-- -- html 주석은 서버에 전달됨 => 중요한 내용은 jsp 주석으로!
    dbip: 192.168.8.3
    user: scott
    password: tiger -- --%>
    
    
    <h3>파일 가져오는 방법 : 2가지</h3>
</body>
</html>
cs

 

 html 주석은 서버에 전달됨 => 중요한 내용은 jsp 주석으로!