쌍용교육(JAVA)/JSP

쌍용교육 -JSP수업 46일차 include

구 승 2024. 4. 23. 16:19

include.jspf

jspf는 include 하는 경우에만 사용한다. HTML을 있는그대로 직접 호출하면 인식이 안됨

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
//공용 변수로 사용하기 위해 변수 선언 및 초기화
String img_path = "./image";
String file_path = "./file";

%>

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file = "include.jspf" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>include 디렉티브</title>
</head>
<body>
이미지 경로 : <%= img_path %><br>
파일 경로 : <%= file_path %>
</body>
</html>

include.jspf에 들어있는 함수를 호출 가능하다. main.jsp에 그대로 들어있는 함수처럼 사용가능.