Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[57] 230321 JSP Ch. 5 ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ, Ch. 6 ์—๋Ÿฌ ์ฒ˜๋ฆฌ, Ch. 7 ํŽ˜์ด์ง€ ๋ชจ๋“ˆํ™”์™€ ์š”์ฒญ ํ๋ฆ„ ์ œ์–ด [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 57์ผ] ๋ณธ๋ฌธ

๐ŸŒณBootcamp Revision 2023โœจ/HTML5, CSS3, JSP

[57] 230321 JSP Ch. 5 ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ, Ch. 6 ์—๋Ÿฌ ์ฒ˜๋ฆฌ, Ch. 7 ํŽ˜์ด์ง€ ๋ชจ๋“ˆํ™”์™€ ์š”์ฒญ ํ๋ฆ„ ์ œ์–ด [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 57์ผ]

yjyuwisely 2023. 3. 21. 12:45

230321 Tue 57th class

Ch. 5 ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ
Ch. 6 ์—๋Ÿฌ ์ฒ˜๋ฆฌ
Ch. 7 ํŽ˜์ด์ง€ ๋ชจ๋“ˆํ™”์™€ ์š”์ฒญ ํ๋ฆ„ ์ œ์–ด

์ง„๋„: p. 80 ~ (๊ต์žฌ: ์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€, ์ €์ž: ์ตœ๋ฒ”๊ท )
์ฑ… ์˜ˆ์ œ ์ฝ”๋“œ: https://github.com/madvirus/jsp23
์ €์ž ๋ธ”๋กœ๊ทธ: https://javacan.tistory.com/

 

์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€ | ์ตœ๋ฒ”๊ท  - ๊ต๋ณด๋ฌธ๊ณ 

์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€ | [์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€]๋Š” JSP 2.3์˜ ์ƒˆ๋กœ์šด ํŠน์ง• ๋ฐ˜์˜๊ณผ JSP๋ฅผ ์ง€์›ํ•˜๋Š” ์š”์†Œ์ธ ์„œ๋ธ”๋ฆฟ๊ณผ ํ‘œํ˜„ ์–ธ์–ด ๋“ฑ์˜ ์ƒˆ๋กœ์šด

product.kyobobook.co.kr


์˜ค๋Š˜ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๊ธฐ์–ตํ•  ๊ฒƒ์„ ์ •๋ฆฌํ–ˆ๋‹ค.


๋ชฐ๋ž๋˜ ๊ฒƒ

flush=False (yes, the default) will wait for the line to complete before printing it.

- ๋ชจ๋“ˆ(module)์ด๋ž€ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ๋กœ, ๊ด€๋ จ๋œ ๋ฐ์ดํ„ฐ์™€ ํ•จ์ˆ˜๋ฅผ ํ•˜๋‚˜๋กœ ๋ฌถ์€ ๋‹จ์œ„๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋ณดํ†ต ํ•˜๋‚˜์˜ ์†Œ์Šค ํŒŒ์ผ์— ๋ชจ๋“  ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š๊ณ , ํ•จ์ˆ˜์˜ ๊ธฐ๋Šฅ๋ณ„๋กœ ๋”ฐ๋กœ ๋ชจ๋“ˆ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ชจ๋“ˆ์„ ํ•ฉ์ณ ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์œ„์ฒ˜๋Ÿผ ํ”„๋กœ๊ทธ๋žจ ์ฝ”๋“œ๋ฅผ ๊ธฐ๋Šฅ๋ณ„๋กœ ๋‚˜๋ˆ ์„œ ๋…๋ฆฝ๋œ ํŒŒ์ผ์— ์ €์žฅํ•˜์—ฌ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์„ ๋ชจ๋“ˆํ™” ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

2023.03.07 - [๐ŸŒณK-Digital Revision 2023โœจ/Python, Flask] - [47] 230307 [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 47์ผ] Ch. 6 Flask๋ฅผ ํ™œ์šฉํ•œ ์„ผ์„œ ์ œ์–ด: 1. Flask ์„ธํŒ…ํ•˜๊ธฐ, 2. Flask ์›น์„œ๋ฒ„ ๊ตฌ์ถ•ํ•˜๊ธฐ, 3. Flask ๋ผ์šฐํŒ…, 4. Flask LED ์ œ์–ดํ•˜๊ธฐ

use the . jsp extension for the source files of complete JSP pages
and use the . jspf extension for the source files of JSP segments.
f(fragment): ํŒŒํŽธ 


PART 2 ํ•„์ˆ˜ ์Šต๋“
Ch. 5 ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ

์ฑ…์˜ ๋ชฉ์ฐจ

01 ๊ธฐ๋ณธ ๊ฐ์ฒด

02 out ๊ธฐ๋ณธ ๊ฐ์ฒด
2.1 out ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์ถœ๋ ฅ ๋ฉ”์„œ๋“œ
2.2 out ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ๋ฒ„ํผ์˜ ๊ด€๊ณ„

03 pageContext ๊ธฐ๋ณธ ๊ฐ์ฒด

3.1 ๊ธฐ๋ณธ ๊ฐ์ฒด ์ ‘๊ทผ ๋ฉ”์„œ๋“œ

04 application ๊ธฐ๋ณธ ๊ฐ์ฒด

4.1 ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ ์ฝ์–ด์˜ค๊ธฐ
4.2 ์„œ๋ฒ„ ์ •๋ณด ์ฝ์–ด์˜ค๊ธฐ
4.3 ๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ๊ธฐ๋กํ•˜๊ธฐ
4.4 ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ž์› ๊ตฌํ•˜๊ธฐ

05 JSP ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ


06 JSP ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ(Attribute) ์‚ฌ์šฉํ•˜๊ธฐ
6.1 ์†์„ฑ์˜ ๊ฐ’ ํƒ€์ž…
6.2 ์†์„ฑ์˜ ํ™œ์šฉ

Ch. 5 ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ p. 114

์•ž์„œ ํ•™์Šตํ•œ request ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ response ๊ธฐ๋ณธ ๊ฐ์ฒด ์ด์™ธ์˜ ๋‚˜๋จธ์ง€ JSP ๊ธฐ๋ณธ ๊ฐ์ฒด์— ๋Œ€ํ•ด์„œ ์‚ดํŽด๋ณธ๋‹ค. 
JSP ํŽ˜์ด์ง€์™€ ๊ด€๋ จ๋œ ๋„ค ๊ฐ€์ง€ ์˜์—ญ๊ณผ ์˜์—ญ๋ณ„๋กœ ์†์„ฑ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ๋ฐฐ์šด๋‹ค

5.1 ๊ธฐ๋ณธ ๊ฐ์ฒด

JSP๋Š” 9๊ฐ€์ง€ ๊ธฐ๋ณธ ๊ฐ์ฒด๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค.

๊ธฐ๋ณธ ๊ฐ์ฒด ์‹ค์ œ ํƒ€์ž… ์„ค๋ช…
request javax.servlet.http.HttpServletRequest ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
response javax.servlet.http.HttpServletResponse ์‘๋‹ต ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
pageContext javax.servlet.jsp.PageContext JSP ํŽ˜์ด์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
session javax.servlet.http.HttpSession HTTP ์„ธ์…˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
application javax.servlet.ServletContext ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
out javax.servlet.jsp.JspWriter JSP ํŽ˜์ด์ง€๊ฐ€ ์ƒ์„ฑํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์ถœ๋ ฅ ์ŠคํŠธ๋ง์ด๋‹ค.
config javax.servlet.ServletConfig JSP ํŽ˜์ด์ง€์— ๋Œ€ํ•œ ์„ค์ • ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
page javax.lang.Object JSP ํŽ˜์ด์ง€๋ฅผ ๊ตฌํ˜„ํ•œ ์ž๋ฐ” ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค์ด๋‹ค.
exception java.lang.Throwable ์ต์„ผ์…ฅ ๊ฐ์ฒด์ด๋‹ค. ์—๋Ÿฌ ํŽ˜์ด์ง€์—๋งŒ ์‚ฌ์šฉํ•œ๋‹ค.

5.2 out ๊ธฐ๋ณธ ๊ฐ์ฒด

1) out ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์ถœ๋ ฅ ๋ฉ”์„œ๋“œ

JSP ํŽ˜์ด์ง€๊ฐ€ ์ƒ์„ฑํ•˜๋Š” ๋ชจ๋“  ๋‚ด์šฉ์€ out ๊ธฐ๋ณธ ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ์ „์†ก๋œ๋‹ค.

์˜ˆ์ œ 5-1) out ๊ธฐ๋ณธ ๊ฐ์ฒด๋ฅผ JSP ํŽ˜์ด์ง€์˜ ์Šคํฌ๋ฆฝํŠธ๋ฆฟ์— ์ง์ ‘ ์‚ฌ์šฉ useOutObject.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>out ๊ธฐ๋ณธ ๊ฐ์ฒด ์‚ฌ์šฉ</title>
</head>
<body>

<% 
	out.println("์•ˆ๋…•ํ•˜์„ธ์š”?"); 
%>
<br>
out ๊ธฐ๋ณธ ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ
<%
	out.println("์ถœ๋ ฅํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.");
%>

</body>
</html>

๊ฑฐ์˜ ์“ฐ์ž„์€ ์—†๋‹ค. 

2) out ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ๋ฒ„ํผ์˜ ๊ด€๊ณ„


5.3 pageContext ๊ธฐ๋ณธ ๊ฐ์ฒด

1) ๊ธฐ๋ณธ ๊ฐ์ฒด ์ ‘๊ทผ ๋ฉ”์„œ๋“œ

5.4 application ๊ธฐ๋ณธ ๊ฐ์ฒด

1) ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ ์ฝ์–ด์˜ค๊ธฐ
2) ์„œ๋ฒ„ ์ •๋ณด ์ฝ์–ด์˜ค๊ธฐ
3) ๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ๊ธฐ๋กํ•˜๊ธฐ
4) ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ž์› ๊ตฌํ•˜๊ธฐ


5.5 JSP ๊ธฐ๋ณธ ๊ฐ์ฒด์™€ ์˜์—ญ p. 132

2023.03.20 - [๐ŸŒณK-Digital Revision 2023โœจ/JSP] - [56] 230320 [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 56์ผ] JSP Ch. 1 ๋“ค์–ด๊ฐ€๊ธฐ, Ch. 2 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ, Ch. 13 ์ดํด๋ฆฝ์Šค๋ฅผ ์ด์šฉํ•œ ์›น ๊ฐœ๋ฐœ

์„ธ์…˜(Session)์ด๋ž€ ์‚ฌ์šฉ์ž๊ฐ€ ์ตœ์ดˆ์— ์„œ๋ฒ„์— ์š”์ฒญํ•œ ์‹œ์ ๋ถ€ํ„ฐ ์ข…๋ฃŒํ•  ๋•Œ๊นŒ์ง€ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋“ค์–ด์˜ค๋Š” ์ผ๋ จ์˜ ์š”๊ตฌ๋ฅผ ํ•˜๋‚˜์˜ ์ƒํƒœ๋กœ ๋ณด๊ณ  ๊ทธ ์ƒํƒœ๋ฅผ ์ผ์ •ํ•˜๊ฒŒ ์œ ์ง€์‹œํ‚ค๋Š” ๊ธฐ์ˆ ์ด๋‹ค.
์ฐธ๊ณ 

์„ธ์…˜์— ์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์žˆ์œผ๋ฉด ๋กœ๊ทธ์ธํ•œ๋‹ค. 
์„ธ์…˜์„ ์“ฐ๋Š” ์ด์œ : ํ•œ ๋ฒˆ ๋กœ๊ทธ์ธ ํ•œ ๋’ค์— ๊ณ„์†์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์“ด๋‹ค. 
์›น๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋‹ซ์œผ๋ฉด ๋‚ ๋ผ๊ฐ„๋‹ค.
(ํ•œ ๋ธŒ๋ผ์šฐ์ € ๋‹น ํ•˜๋‚˜์˜ ์„ธ์…˜์ด๋‹ค.: ํฌ๋กฌ์œผ๋กœ ๋„ค์ด๋ฒ„ ๋กœ๊ทธ์ธํ•ด๋„, ๋งˆ์ดํฌ๋กœ์†Œํ”„ํŠธ ์—ฃ์ง€์—๋Š” ๋กœ๊ทธ์ธ ์•ˆ ๋œ ๊ฑธ๋กœ ๋œฌ๋‹ค.)

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์˜์—ญ ex) ๋ฐฉ๋ฌธ์ž ์ˆ˜๊ฐ€ ๋ˆ„์ ๋œ๋‹ค.
์„œ๋ฒ„๋ฅผ ์ฃฝ์ด๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์•ˆ์˜ ๋ฐ์ดํ„ฐ๋“ค์ด ๋‹ค ๋‚ ๋ผ๊ฐ„๋‹ค. (์„ธ์…˜์€ ๋‹ซ์œผ๋ฉด ๋‚ ๋ผ๊ฐ€๋Š” ๊ฒƒ๊ณผ๋Š” ๋‹ค๋ฅด๋‹ค.)  

- PAGE ์˜์—ญ: ํ•˜๋‚˜์˜ JSP ํŽ˜์ด์ง€๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ์˜์—ญ
ํ•œ ๋ฒˆ์˜ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ํ•˜๋‚˜์˜ JSP ํŽ˜์ด์ง€๋ฅผ ๋ฒ”์œ„๋กœ ๊ฐ–๋Š”๋‹ค.
์›น ๋ธŒ๋ผ์šฐ์ €์˜ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด JSP ํŽ˜์ด์ง€๋ฅผ ์‹คํ–‰ํ•˜๋Š”๋ฐ, ์ด๋•Œ JSP ํŽ˜์ด์ง€๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฒ”์œ„๊ฐ€ ํ•˜๋‚˜์˜ PAGE ์˜์—ญ์ด ๋œ๋‹ค.

- REQUEST ์˜์—ญ:
ํ•˜๋‚˜์˜ HTTP ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ์˜์—ญ 
ํ•œ ๋ฒˆ์˜ ์›น ๋ธŒ๋ผ์šฐ์ € ์š”์ฒญ๊ณผ ๊ด€๋ จ๋œ๋‹ค.
์›น ๋ธŒ๋ผ์šฐ์ €์˜ ์ฃผ์†Œ์— URL์„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•ด์„œ ํŽ˜์ด์ง€๋ฅผ ์ด๋™ํ•  ๋•Œ, ์›น ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์›น ์„œ๋ฒ„์— ์ „์†กํ•˜๋Š” ์š”์ฒญ์ด ํ•˜๋‚˜์˜ REQUEST ์˜์—ญ์ด ๋œ๋‹ค. 
์›น ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ์šด REQUEST ์˜์—ญ์ด ์ƒ์„ฑ๋œ๋‹ค. 

- SESSION ์˜์—ญ:
 ํ•˜๋‚˜์˜ ์›น ๋ธŒ๋ผ์šฐ์ €์™€ ๊ด€๋ จ๋œ ์˜์—ญ์ด๋‹ค. ์„ธ์…˜์ด ์ƒ์„ฑ๋˜๋ฉด ํ•˜๋‚˜์˜ ์›น ๋ธŒ๋ผ์šฐ์ €์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  ์š”์ฒญ์€ ํ•˜๋‚˜์˜ SESSION ์˜์—ญ์— ํฌํ•จ๋œ๋‹ค.


- APPLICATION ์˜์—ญ: ํ•˜๋‚˜์˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ๊ด€๋ จ๋œ ์ „์ฒด ์˜์—ญ์„ ํฌํ•จํ•œ๋‹ค. 

๋„ค ๊ฐ€์ง€ ์˜์—ญ๊ณผ ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ๊ด€๊ณ„

๊ทธ๋ฆผ ์ถœ์ฒ˜


5.6 JSP ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ(Attribute) ์‚ฌ์šฉํ•˜๊ธฐ

์˜ˆ์ œ) ApplicationForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>application ํผ</title>
</head>
<body>
<form action="setApplicationAttribute.jsp">
	์ด๋ฆ„: <input type="text" name="name">
	๊ฐ’: <input type="text" name="value">
	<input type="submit" value="์ „์†ก">
</form>
</body>
</html>

์ด๋ฆ„์— attr1, ๊ฐ’์— val1์„ ๋„ฃ์—ˆ๋‹ค.

์˜ˆ์ œ 5-13) application ๊ธฐ๋ณธ ๊ฐ์ฒด์— ์†์„ฑ๊ฐ’์„ ์ถ”๊ฐ€ํ•ด ์ฃผ๋Š” JSPํŽ˜์ด์ง€ setApplicationAttribute.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
	String name = request.getParameter("name");
	String value = request.getParameter("value");
	
	if (name != null && value != null) {
		application.setAttribute(name, value);
	}
%>
<html>
<head>
<meta charset="UTF-8">
<title>application ์†์„ฑ ์ง€์ •</title>
</head>
<body>
<%
	if (name != null && value != null){
%>
application ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ ์„ค์ •:
<%= name %> = <%= value %>
<%
} else {
%>
application ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ ์„ค์ • ์•ˆ ํ•จ
<%
	}
%>
</body>
</html>

์˜์—ญ์€ ์„œ๋ฒ„๋ฅผ ์ฃฝ์ด์ง€ ์•Š๋Š” ์ด์ƒ ๊ทธ๋Œ€๋กœ ๋‚จ์•„์žˆ๋‹ค.

http://localhost:8081/JSPExample/ch05/setApplicationAttribute.jsp?name=attr1&value=val1

์ฐฝ์„ ๋‹ซ์•„๋„ ์œ„ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ทธ๋Œ€๋กœ ๋œฌ๋‹ค. 
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์˜์—ญ์€ ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋‹ซ์•„๋„ ๊ทธ๋Œ€๋กœ ๋‚จ์•„์žˆ๋‹ค.


1) ์†์„ฑ์˜ ๊ฐ’ ํƒ€์ž…

2) ์†์„ฑ์˜ ํ™œ์šฉ


Ch. 6 ์—๋Ÿฌ ์ฒ˜๋ฆฌ p. 140

์ฑ…์˜ ๋ชฉ์ฐจ
01 ์ต์…‰์…˜ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜๊ธฐ
02 ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ
03 ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ž‘์„ฑํ•˜๊ธฐ
04 ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ๋ณ„๋กœ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ
05 ์ต์…‰์…˜ ํƒ€์ž…๋ณ„๋กœ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ
06 ์—๋Ÿฌ ํŽ˜์ด์ง€์˜ ์šฐ์„ ์ˆœ์œ„์™€ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ • ํ˜•ํƒœ
07 ๋ฒ„ํผ์™€ ์—๋Ÿฌ ํŽ˜์ด์ง€์˜ ๊ด€๊ณ„

์ต์…‰์…˜ ์ฒ˜๋ฆฌ

- try{์—๋Ÿฌ ๋ฐœ์ƒ}catch{์—๋Ÿฌ ์ฒ˜๋ฆฌ}
- ์—๋Ÿฌ ํŽ˜์ด์ง€
<%@ page errorPage = "์—๋ŸฌํŽ˜์ด์ง€.jsp" %>

6.1 ์ต์…‰์…˜ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜๊ธฐ

์˜ˆ์ œ 6-2) try-catch๋ฅผ ์ด์šฉํ•ด์„œ ์ต์…‰์…˜์ด ๋ฐœ์ƒํ•  ๋•Œ ์•Œ๋งž์€ ์‘๋‹ต์„ ์ƒ์„ฑํ•˜๊ธฐ readParameterWithTry.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํŒŒ๋ผ๋ฏธํ„ฐ ์ถœ๋ ฅ</title>
</head>
<body>

name ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’: 
<% try { %>
<%= request.getParameter("name").toUpperCase() %>
<% } catch(Exception ex) { %>
name ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
<% } %>
</body>
</html>

๊ฒฐ๊ณผ)


6.2 ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ

์—๋Ÿฌ ํ™”๋ฉด ๋Œ€์‹  ์ง€์ •ํ•œ JSP ํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.
์•„๋ž˜์ฒ˜๋Ÿผ page ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ errorPage ์†์„ฑ์„ ์‚ฌ์šฉํ•ด์„œ ์ง€์ •ํ•œ๋‹ค.

<%@ page errorPage = "viewErrorMessage.jsp" %>

์˜ˆ์ œ 6-3) ์—๋Ÿฌ ํŽ˜์ด์ง€๋ฅผ ์ง€์ •ํ•˜๋Š” ์˜ˆ readParameter.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page errorPage = "viewErrorMessage.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํŒŒ๋ผ๋ฏธํ„ฐ ์ถœ๋ ฅ</title>
</head>
<body>

name ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’: <%= request.getParameter("name").toUpperCase() %>

</body>
</html>

6.3 ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ž‘์„ฑํ•˜๊ธฐ p. 144

์˜ˆ์ œ 6-4) ์•ž์˜ ์˜ˆ์ œ 6-3)์ด ์ง€์ •ํ•œ ์—๋Ÿฌ ํŽ˜์ด์ง€ viewErrorMessage.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page isErrorPage = "true" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์—๋Ÿฌ ๋ฐœ์ƒ</title>
</head>
<body>

์š”์ฒญ ์ฒ˜๋ฆฌ ๊ณผ์ •์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.<br>
๋น ๋ฅธ ์‹œ๊ฐ„ ๋‚ด์— ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
<p>
์—๋Ÿฌ ํƒ€์ž…: <%= exception.getClass().getName() %> <br>
์—๋Ÿฌ ๋ฉ”์‹œ์ง€: <b><%= exception.getMessage() %></b>
</body>
</html>

๊ฒฐ๊ณผ) 


6.4 ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ๋ณ„๋กœ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ p. 147

์—๋Ÿฌ ์ฝ”๋“œ์— ๋Œ€ํ•ด ๋ณด์—ฌ์ค„ ์—๋Ÿฌ ํŽ˜์ด์ง€๋ฅผ ์ง€์ •ํ•˜๋ ค๋ฉด web.xml ํŒŒ์ผ์— ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์ดํด๋ฆฌ์Šค์˜ Servers ํด๋”์— ์žˆ๋Š” web.xml

์ž˜๋ชป ๊ฑด๋“ค๋ฉด ์„œ๋ฒ„๊ฐ€ ์•ˆ ๋Œ์•„๊ฐˆ ์ˆ˜๋„ ์žˆ์œผ๋ฏ€๋กœ ์‹ ์ค‘ํ•˜๊ฒŒ ์ž…๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ 6-5) web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

	<error-page>
		<error-code>404</error-code>
		<location>/error/error404.jsp</location>
	</error-page>

	<error-page>
		<error-code>500</error-code>
		<location>/error/error500.jsp</location>
	</error-page>

	<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/error/errorNullPointer.jsp</location>
	</error-page>

</web-app>

6.5 ์ต์…‰์…˜ ํƒ€์ž…๋ณ„๋กœ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ •ํ•˜๊ธฐ


6.6 ์—๋Ÿฌ ํŽ˜์ด์ง€์˜ ์šฐ์„ ์ˆœ์œ„์™€ ์—๋Ÿฌ ํŽ˜์ด์ง€ ์ง€์ • ํ˜•ํƒœ


6.7 ๋ฒ„ํผ์™€ ์—๋Ÿฌ ํŽ˜์ด์ง€์˜ ๊ด€๊ณ„


Ch. 7 ํŽ˜์ด์ง€ ๋ชจ๋“ˆํ™”์™€ ์š”์ฒญ ํ๋ฆ„ ์ œ์–ด

์ฑ…์˜ ๋ชฉ์ฐจ
01 <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ๊ณตํ†ต ์˜์—ญ ์ž‘์„ฑ
1.1 <jsp:include> ์•ก์…˜ ํƒœ๊ทธ ์‚ฌ์šฉ๋ฒ•
1.2 <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ์ค‘๋ณต ์˜์—ญ ์ฒ˜๋ฆฌ
1.3 <jsp:param>์œผ๋กœ ํฌํ•จํ•  ํŽ˜์ด์ง€์— ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€ํ•˜๊ธฐ
1.4 <jsp:param> ์•ก์…˜ ํƒœ๊ทธ์™€ ์บ๋ฆญํ„ฐ ์ธ์ฝ”๋”ฉ

02 include ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์ด์šฉํ•œ ์ค‘๋ณต๋œ ์ฝ”๋“œ ์‚ฝ์ž…
2.1 include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ์‹๊ณผ ํ™œ์šฉ๋ฒ•
2.2 include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ํ™œ์šฉ
2.3 ์ฝ”๋“œ ์กฐ๊ฐ ์ž๋™ ํฌํ•จ ๊ธฐ๋Šฅ
2.4 <jsp:include> ์•ก์…˜ ํƒœ๊ทธ์™€ include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ๋น„๊ต

03 <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ JSP ํŽ˜์ด์ง€ ์ด๋™
3.1 <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ ์‚ฌ์šฉ๋ฒ•
3.2 <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์™€ ์ถœ๋ ฅ ๋ฒ„ํผ์™€์˜ ๊ด€๊ณ„
3.3 <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ ํ™œ์šฉ
3.4 <jsp:param> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ์ด๋™ํ•  ํŽ˜์ด์ง€์— ๋”ฐ๋ผ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€ํ•˜๊ธฐ 

04 <jsp:include>์™€ <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ page ์†์„ฑ ๊ฒฝ๋กœ

05 ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ด์šฉํ•ด์„œ ๊ฐ’ ์ „๋‹ฌํ•˜๊ธฐ

<jsp:include> ์•ก์…˜ ํƒœ๊ทธ์™€ include ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ค‘๋ณต๋œ ์ฝ”๋“œ ์—†์ด ์—ฌ๋Ÿฌ JSP ์ฝ”๋“œ์— ๊ณตํ†ต๋œ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. 
<jsp:forward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ๋‹ค๋ฅธ JSP๋กœ ์š”์ฒญ ์ฒ˜๋ฆฌ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณธ๋‹ค. 

7.1 <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ๊ณตํ†ต ์˜์—ญ ์ž‘์„ฑ p. 155

ํ™”๋ฉด ๊ตฌ์„ฑ ์š”์†Œ์˜ ์ฝ”๋“œ ์ค‘๋ณต ๋ฌธ์ œ๋ฅผ ์—†์•จ ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ <jsp:include> ์•ก์…˜ ํƒœ๊ทธ์ด๋‹ค.


1) <jsp:include> ์•ก์…˜ ํƒœ๊ทธ ์‚ฌ์šฉ๋ฒ•

๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

<jsp:include page="ํฌํ•จํ• ํŽ˜์ด์ง€" flush="true" />

์˜ˆ์ œ 7-1) <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์ œ main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main</title>
</head>
<body>

main.jsp์—์„œ ์ƒ์„ฑํ•œ ๋‚ด์šฉ

<jsp:include page="sub.jsp" flush="false" />

include ์ดํ›„์˜ ๋‚ด์šฉ.

</body>
</html>

์˜ˆ์ œ 7.2) ์ˆ˜์ • ์ „ sub.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>

<p>
sub.jsp์—์„œ ์ƒ์„ฑํ•œ ๋‚ด์šฉ
</p>

</body>
</html>

๊ฒฐ๊ณผ)

ํŽ˜์ด์ง€ ์†Œ์Šค ๋ณด๊ธฐ ํด๋ฆญ

์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฏ€๋กœ <p> ~ </p>๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ์ง€์šด๋‹ค.

์˜ˆ์ œ 7.2) ์ˆ˜์ • ํ›„ sub.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<p>
sub.jsp์—์„œ ์ƒ์„ฑํ•œ ๋‚ด์šฉ
</p>

๊ฒฐ๊ณผ)

ํŽ˜์ด์ง€ ์†Œ์Šค ๋ณด๊ธฐ ํด๋ฆญ


2) <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ ์ค‘๋ณต ์˜์—ญ ์ฒ˜๋ฆฌ p. 158

์ƒ๋‹จ
์ขŒ์ธก๋ฉ”๋‰ด ์ค‘์•™๋‚ด์šฉ
ํ•˜๋‹จ

ํ‘œ, <div> ๋“ฑ ์–ด๋–ค ๋ฐฉ๋ฒ•์œผ๋กœ ๋ ˆ์ด์•„์›ƒ ์žก์•„๋„ ๋œ๋‹ค.
์˜ˆ์‹œ)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>layout1</title>
</head>
<body>
<table border="1">
<tr>
	<td colspan="2"> ์ƒ๋‹จ
	</td>
</tr>
<tr>
	<td> ์ขŒ์ธก๋ฉ”๋‰ด </td>
	<td> ์ค‘์•™๋ฉ”๋‰ด </td>
</tr>
<tr>
	<td colspan="2"> ํ•˜๋‹จ</td>
</tr>
</table>
</body>
</html>

๊ฒฐ๊ณผ) 


์˜ˆ์‹œ) ์ƒ๋‹จ ๊ด€๋ จ ์ฝ”๋“œ top.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

์ƒ๋‹จ ๋ฉ”๋‰ด: ํ™ˆ ์ •๋ณด

์˜ˆ์‹œ) ์ขŒ์ธก ๊ด€๋ จ ์ฝ”๋“œ left.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

์ขŒ์ธก ๋ฉ”๋‰ด:

์˜ˆ์‹œ) ํ•˜๋‹จ ๊ด€๋ จ ์ฝ”๋“œ bottom.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

ํ•˜๋‹จ ๋ฉ”๋‰ด: ์†Œ๊ฐœ | ๋„์›€๋ง | ์•ฝ๊ด€ | ์‚ฌ์ดํŠธ๋งต

์˜ˆ์‹œ 7-4) <jsp:include> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŽ˜์ด์ง€์˜ ๊ณตํ†ต ๋ถ€๋ถ„์„ ์ฝ์–ด์˜ค๋Š” ์˜ˆ layout.jsp
flush=False (yes, the default) will wait for the line to complete before printing it.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>layout1</title>
</head>
<body>
<table border="1">
<tr>
	<td colspan="2"> 
	<jsp:include page="top.jsp" flush="false" />
	</td>
</tr>
<tr>
	<td> <jsp:include page="left.jsp" flush="false" /> </td> 
	<td> ์ค‘์•™๋ฉ”๋‰ด </td>
</tr>
<tr>
	<td colspan="2"><jsp:include page="bottom.jsp" flush="false"/></td>
</tr>
</table>
</body>
</html>

๊ฒฐ๊ณผ) 


3) <jsp:param>์œผ๋กœ ํฌํ•จํ•  ํŽ˜์ด์ง€์— ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€ํ•˜๊ธฐ

<jsp:include page="infoSub.jsp" flush="false">
	<jsp:param name="type" value="A" />
</jsp:include>

์˜ˆ์ œ 7-6) <jsp:param> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ infoSub.jsp์— ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ถ”๊ฐ€๋กœ ์ „๋‹ฌํ•˜๋Š” ์˜ˆ info.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>INFO</title>
</head>
<body>
<table border="1">
<tr>
	<td>์ œํ’ˆ๋ฒˆํ˜ธ</td> <td>XXXX</td>
</tr>
<tr>
	<td>๊ฐ€๊ฒฉ</td> <td>10,000์›</td>
</tr>
</table>

<jsp:include page="infoSub.jsp" flush="false">
	<jsp:param name="type" value="A" />
</jsp:include>
</html>

์˜ˆ์ œ 7-7) ์ œํ’ˆ์˜ ํƒ€์ž…๋ณ„๋กœ ์ถ”๊ฐ€ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ด์ฃผ๋Š” ํ™”๋ฉด infosub.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String type = request.getParameter("type");
	if (type == null) {
		return;
	}
%>
<br>
<table border="1">
<tr>
	<td>ํƒ€์ž…</td>
	<td><b><%= type %></b></td>
</tr>
<tr>
	<td>ํŠน์ง•</td>
	<td>
<%  if (type.equals("A")) { %>
	๊ฐ•ํ•œ ๋‚ด๊ตฌ์„ฑ.
<%  } else if (type.equals("B")) { %>
	๋›ฐ์–ด๋‚œ ๋Œ€์ฒ˜ ๋Šฅ๋ ฅ
<%  } %>
	</td>
</tr>
</table>

๊ฒฐ๊ณผ)

ํƒ€์ž…์ด A์ด๋ฏ€๋กœ infoSub.jsp์— ์žˆ๋Š” ๊ฐ•ํ•œ ๋‚ด๊ตฌ์„ฑ.์ด ์ถœ๋ ฅ๋œ๋‹ค.


4) <jsp:param> ์•ก์…˜ ํƒœ๊ทธ์™€ ์บ๋ฆญํ„ฐ ์ธ์ฝ”๋”ฉ


7.2 include ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์ด์šฉํ•œ ์ค‘๋ณต๋œ ์ฝ”๋“œ ์‚ฝ์ž…

include ๋””๋ ‰ํ‹ฐ๋ธŒ๋„ <jsp:include> ์•ก์…˜ ํƒœ๊ทธ์ฒ˜๋Ÿผ ์ง€์ •ํ•œ ํŽ˜์ด์ง€๋ฅผ ํ˜„์žฌ ์œ„์น˜์— ํฌํ•จ์‹œํ‚ค๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. ํ•˜์ง€๋งŒ ํฌํ•จํ•˜๋Š” ๋ฐฉ์‹์— ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.
<jsp: include> ์•ก์…˜ ํƒœ๊ทธ๋Š” ๋‹ค๋ฅธ JSP๋กœ ์‹คํ–‰ ํ๋ฆ„์„ ์ด๋™์‹œ์ผœ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ํ˜„์žฌ ์œ„์น˜์— ํฌํ•จํ•˜๋Š” ๋ฐฉ์‹์ธ ๋ฐ˜๋ฉด์—, include ๋””๋ ‰ํ‹ฐ๋ธŒ๋Š” ๋‹ค๋ฅธ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ํ˜„์žฌ ์œ„์น˜์— ์‚ฝ์ž…ํ•œ ํ›„์— JSP ํŒŒ์ผ์„ ์ž๋ฐ” ํŒŒ์ผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์ปดํŒŒ์ผํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.


1) include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ์‹๊ณผ ํ™œ์šฉ๋ฒ• p. 169

include: ํฌํ•จ์‹œํ‚ค๋‹ค.
forward: ์ด๋™์‹œํ‚ค๋‹ค. ๋ผ๋Š” ๊ฐœ๋…์ด๋‹ค.

include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

<%@ include file="ํฌํ•จํ• ํŒŒ์ผ" %>

 

์˜ˆ์ œ 7-10) include ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ ์ฝ”๋“œ includer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>include ๋””๋ ‰ํ‹ฐ๋ธŒ</title>
</head>
<body>

<%
	int number = 10;
%>

<%@ include file="includee.jsp" %>
๊ณตํ†ต๋ณ€์ˆ˜ DATAFOLDER = "<%= dataFolder %>"
</body>
</html>

์˜ˆ์ œ 7-11) dataFolder ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ์ฝ”๋“œ includee.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
includer.jsp์—์„œ ์ง€์ •ํ•œ ๋ฒˆํ˜ธ: <%= number %>
<p>
<%
	String dataFolder = "c:\\data";
%>

๊ฒฐ๊ณผ)


2) include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ํ™œ์šฉ
3) ์ฝ”๋“œ ์กฐ๊ฐ ์ž๋™ ํฌํ•จ ๊ธฐ๋Šฅ
4) <jsp:include> ์•ก์…˜ ํƒœ๊ทธ์™€ include ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ ๋น„๊ต


7.3 <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ JSP ํŽ˜์ด์ง€ ์ด๋™


1) <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ ์‚ฌ์šฉ๋ฒ• p. 179

์˜ˆ์ œ 7-18) <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์ œ from.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%--
	<jsp:foward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด
	์ƒ์„ฑํ–ˆ๋˜ ์ถœ๋ ฅ ๊ฒฐ๊ณผ๋Š” ๋ชจ๋‘ ์ œ๊ฑฐ๋œ๋‹ค.
--%>
<html>
<head><title>from.jsp์˜ ์ œ๋ชฉ</title></head>
<body>

์ด ํŽ˜์ด์ง€๋Š” from.jsp๊ฐ€ ์ƒ์„ฑํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

<jsp:forward page="to.jsp" />

</body>
</html>

์˜ˆ์ œ 7-19) to.jsp
์˜ˆ์ œ 7-18)์— ์žˆ๋Š” <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ to.jsp๋กœ ์‹คํ–‰ ํ๋ฆ„์„ ์ด๋™์‹œํ‚ค๊ณ  ์žˆ๋‹ค. 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head><title>to.jsp์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ</title></head>
<body>

์ด ํŽ˜์ด์ง€๋Š” to.jsp๊ฐ€ ์ƒ์„ฑํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

</body>
</html>

๊ฒฐ๊ณผ)


2) <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์™€ ์ถœ๋ ฅ ๋ฒ„ํผ์™€์˜ ๊ด€๊ณ„


3) <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ ํ™œ์šฉ


4) <jsp:param> ์•ก์…˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ์ด๋™ํ•  ํŽ˜์ด์ง€์— ๋”ฐ๋ผ ํŒŒ๋ผ๋ฏธํ„ฐ ์ถ”๊ฐ€ํ•˜๊ธฐ


7.4 <jsp:include>์™€ <jsp:forward> ์•ก์…˜ ํƒœ๊ทธ์˜ page ์†์„ฑ ๊ฒฝ๋กœ


7.5 ๊ธฐ๋ณธ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์ด์šฉํ•ด์„œ ๊ฐ’ ์ „๋‹ฌํ•˜๊ธฐ


728x90
๋ฐ˜์‘ํ˜•
Comments