include Directive
<%@ include%>
여러 JSP 페이지에서 공통적으로 사용되는 내용이 있을 때, 이러한 내용을 별도의 파일로 저장해 두었다가 필요한 JSP 페이지 내에 삽입할 수 있는 기능을 제공한다.
예) <%@ include file="포함될 파일의 URL"%>
includeDirective.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>include Directive 연습</title>
</head>
<body>
<h2>include Directive 연습</h2>
<%
String name = "Kim";
%>
<%@ include file="top.jsp"%>
포함하는 페이지 includeDirective.jsp의 내용입니다.
<%@ include file="bottom.jsp"%>
</body>
</html>
top.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.Timestamp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>top.jsp</title>
</head>
<body>
<%
Timestamp now = new Timestamp(System.currentTimeMillis());
%>
top.jsp 입니다. <p>
<%=now.toString() %>
<hr>
</body>
</html>
bottom.jsp
<!DOCTYPE html>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta charset="UTF-8">
<title>bottom.jsp</title>
</head>
<body>
<hr>
bottom.jsp 입니다. <p>
작성자는 <b><%=name %></b> 입니다.
</body>
</html>

'Web Programming > JSP' 카테고리의 다른 글
| [JSP] 기본 제어문 (0) | 2024.10.02 |
|---|---|
| [JSP] taglib Directive (1) | 2024.09.30 |
| [JSP] Page Directive (0) | 2024.09.30 |
| [JSP] JAVA 기초 문법 (0) | 2024.09.27 |
| [JSP] JSP 동작원리(톰켓)와 서블릿 (2) | 2024.09.27 |