개발자의 길/JSP
JSP include Directive(지시자)
모쿠
2017. 4. 12. 14:39
<지시자를 이용한 파일 포함>
include 지시자(directive) 동작 원리:
- include를 사용해서 다른 파일(jsp, jspf)을 포함시키면, 하나의 JSP 파일로 합쳐진 이후에, 서블릿 클래스로 변환
<header.jspf>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <style> .header { background-color: lightgreen; font-size: 200%; text-align: center; height: 60px; } </style> <div class="header"> 여기는 Header입니다... </div> | cs |
<footer.jspf>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <style> .footer { background-color: lightblue; text-align: center; height: 60px; } </style> <div class="footer"> (주) 무한상사<br/> http://www.무한상사.co.kr<br/> TEL: 02-1132-3333 </div> | cs |
<04_include>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSP</title> </head> <body> <%-- header 파일을 include --%> <%@ include file="header.jspf" %> <h1>include Directive(지시자)</h1> <div><p>본문입니다....</p></div> <%-- footer 파일을 include --%> <%@ include file="footer.jspf" %> </body> </html> | cs |
<출력화면>