BACK-END/JSP

[JSP] include Directive(지시자)

이리53 2022. 3. 23. 15:44

include Directive

  • 특정 jsp 파일을 페이지에 포함
  • 여러 jsp 페이지에서 반복적으로 사용되는 부분을 jsp 파일로 분리하여 해당 영역에 include 시켜 사용
  • 동적, 정적으로 나뉨
  • 동적 include : 해당 jsp의 실행 결과물을 include
</jsp:include page="header.jsp">
  • 정적 include : 해당 jsp 내용을 그대로 include. include 하는 곳에 duplicated 된 것 없도록 주의
<%@ include file="./header.jsp" %>
  • 아래의 예제는 정적 include 에 대해서만 다룸

 

 

 

header.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<header style="background-color: #93DAFF">
	<h1>This is header</h1>
</header>

http://localhost:8080/bw/include_test/header.jsp

 

 

footer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<footer style="background-color: #FFB6C1">
	<h1>This is footer</h1>
</footer>

 

http://localhost:8080/bw/include_test/footer.jsp

 

 

index.jsp

<%@ 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>

<%@ include file="./header.jsp" %>

<div style="background-color: #d2d2d2">
	<h1>This is main</h1>
</div>

<%@ include file="./footer.jsp" %>

</body>
</html>

 

http://localhost:8080/bw/include_test/index.jsp

 

'BACK-END > JSP' 카테고리의 다른 글

[JSP] cookie  (0) 2022.03.24
[JSP] session  (0) 2022.03.23
[JSP] forward, sendRedirect  (0) 2022.03.23