Include

์ฝœ๋ผ๋ง˜ยท2023๋…„ 6์›” 27์ผ
0

JSP

๋ชฉ๋ก ๋ณด๊ธฐ
15/17
post-thumbnail

๐Ÿ JSP include

  • ํฌ์›Œ๋“œ์ฒ˜๋Ÿผ request์™€ response๋ฅผ ๋‹ค๋ฅธ jsp๋กœ ๋ณด๋ƒˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ๋Œ์•„์˜ค๋Š” ๊ธฐ๋Šฅ
  • ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋กœ ์ž ๊น ๊ฐ”๋‹ค ๋Œ์•„์˜ค๋Š” ๊ธฐ๋Šฅ์ด๊ธฐ ๋•Œ๋ฌธ์— page scope์˜ ๊ฐ’์„ ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์—†๋‹ค

๐Ÿ File include

  • ํ•ด๋‹น ํŒŒ์ผ ๋‚ด์šฉ์„ ์ฝ์–ด์„œ ํ˜„์žฌ jsp ๋‚ด๋ถ€์— ํฌํ•จ์‹œํ‚ค๋Š” ๊ธฐ๋Šฅ
  • ์ปดํŒŒ์ผ ์ด์ „์— ํŒŒ์ผ ๋‚ด์šฉ์„ ํฌํ•จ์‹œํ‚จ ํ›„ ์ปดํŒŒ์ผ์„ ์ง„ํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค
  • page scope์˜ ๊ฐ’์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค

๐Ÿคบ JSP include ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

โœ” main.jsp >>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!-- ์—ฌ๊ธฐ๋Š”...Servlet extends HttpServlet ์ด ์ƒ๋žต๋˜์–ด ์žˆ์Œ -->    
<jsp:include page="/include/top.jsp"></jsp:include> 
<h1>์ œ๋ชฉ</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
 Quod ullam placeat cum pariatur at nulla eum iure neque rerum 
 corrupti veritatis fuga doloremque esse explicabo ut quia aspernatur numquam enim.
 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatum dignissimos 
 molestias aspernatur voluptatem iure officia cumque fugit neque sint excepturi ut 
 eaque facilis rem illo at nostrum qui odit ab!</p>
 <!-- contextpath๋Š” ์ƒ๋žต ๊ฐ€๋Šฅ / webapp ์•„๋ž˜์˜ ๊ฒฝ๋กœ๋ฅผ ์ค˜์•ผํ•จ -->
 <jsp:include page="/include/bottom.jsp"></jsp:include>

โœ” top.jsp >>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Top.jsp์—์„œ ์ •ํ•œ ์ œ๋ชฉ</title>
</head>
<body>
<table border="1">
	<tr>
		<th>๋ฉ”๋‰ด์†Œ๊ฐœ</th>
		<th>์ฐพ์•„์˜ค์‹œ๋Š” ๊ธธ</th>
		<th>์ฒด์ธ์ </th>
		<th>์‚ฌ์ดํŠธ๋งต</th>
		<th>๊ณ ๊ฐ์„ผํ„ฐ</th>
	</tr>
	<tr>
		<th>
			<ul>
				<li>Side menu1</li>
				<li>Side menu2</li>
				<li>Side menu3</li>
				<li>Side menu4</li>
				<li>Side menu5</li>
			</ul>		
		</th>
		<td colspan="4">
<!-- ์—ฌ๊ธฐ๋Š” top.jsp์ด๊ธฐ ๋•Œ๋ฌธ์— ์ดํ•˜๋Š” ์ง€์›Œ๋„๋œ๋‹ค -->

โœ” bottom.jsp >>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
		</td>
	</tr>
	<tr>
		<th colspan="5">
			์ „ํ™”๋ฒˆํ˜ธ : 123-1234-1234 | ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ : 123-123-123
			| FAX : 1234-123-1234 ...
		</th>
	</tr>
</table>
</body>
</html>

๐Ÿ“บ main.jsp ์‹คํ–‰ ๊ฒฐ๊ณผ >>

profile
์ฝœ๋ผ๋ง˜ ์ฝ”๋”ฉ์ผ๊ธฐ

0๊ฐœ์˜ ๋Œ“๊ธ€