JSP ์ƒ๋ช… ์ฃผ๊ธฐ๋ผ ํ•จ์€ JSP ์ƒ์„ฑ์—์„œ๋ถ€ํ„ฐ ์†Œ๋ฉธ๊นŒ์ง€์˜ ๊ณผ์ •์„ ๋งํ•˜๋Š”๋ฐ ์ด๋Š” ์„œ๋ธ”๋ฆฟ ์ƒ๋ช…์ฃผ๊ธฐ์™€ ๋งค์šฐ ์œ ์‚ฌํ•˜๊ณ  ์ถ”๊ฐ€์ ์œผ๋กœ JSP๋ฅผ ์ปดํŒŒ์ผ ํ•˜๋Š” ๊ณผ์ •๋งŒ ์ถ”๊ฐ€๋œ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

ํฐ ๊ณผ์ •๋งŒ ๊ฐ„์ถ”๋ฆฌ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

  • Compilation ( ์ปดํŒŒ์ผ ) 

  • Initialization ( ์ดˆ๊ธฐํ™” ) 

  • Execution ( ์‹คํ–‰ ) 

  • Cleanup ( ๋’ท์ •๋ฆฌ ) 

๊ทธ๋ฆผ์œผ๋กœ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์„œ๋ธ”๋ฆฟ ์ƒ๋ช…์ฃผ๊ธฐ์—์„œ ์ปดํŒŒ์ผ๋งŒ ์ถ”๊ฐ€๋œ ๊ฒƒ์ด์ฃ . ์•„๋ž˜ ๊ทธ๋ฆผ์—๋Š” ์ปดํŒŒ์ผ ๊ณผ์ •์€ ์ƒ๋žต๋˜์–ด์žˆ๋„ค์š”. 

JSP Compilation:

์›น๋ธŒ๋ผ์šฐ์ €๊ฐ€ JSP๋ฅผ ์š”์ฒญํ•˜๋ฉด JSP engine ์€ ์šฐ์„  ์š”์ฒญํ•œ JSPํŒŒ์ผ์ด ์ปดํŒŒ์ผ์ด ํ•„์š”ํ•œ์ง€๋ฅผ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ•œ๋ฒˆ๋„ ์ปดํŒŒ์ผ ๋œ์ ์ด ์—†๊ฑฐ๋‚˜ ์ˆ˜์ •๋œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด JSP engine ์ด ์ปดํŒŒ์ผ์„ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.  

์ปดํŒŒ์ผ ๊ณผ์ •์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Parsing the JSP. ( JSP ํŒŒ์ผ ํŒŒ์‹ฑ ) 

  • Turning the JSP into a servlet. ( JSP๋ฅผ ์„œ๋ธ”๋ฆฟ์œผ๋กœ ๋ณ€ํ™˜ ) 

  • Compiling the servlet. ( ์„œ๋ธ”๋ฆฟ ์ปดํŒŒ์ผ ) 

JSP Initialization ( ์ดˆ๊ธฐํ™” )

์ปจํ…Œ์ด๋„ˆ๊ฐ€ JSP๋ฅผ ๋กœ๋“œํ•  ๋•Œ jspInit() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์ „์— ๋ง์ด์ฃ . ๋งŒ์•ฝ ํŠน์ • JSP์—์„œ ํŠน์ˆ˜ํ•œ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋ฉด ์ด jspInit() ๋ฉ”์†Œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

public void jspInit(){ // Initialization code... }

์ผ๋ฐ˜์ ์œผ๋กœ ์ดˆ๊ธฐํ™”๋Š” ์„œ๋ธ”๋ฆฟ ์ดˆ๊ธฐํ™”์ฒ˜๋Ÿผ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰์ด ๋ฉ๋‹ˆ๋‹ค, ์ด ์ดˆ๊ธฐํ™” ๊ณผ์ •์—์„œ ๊ฐœ๋ฐœ์ž๋“ค์€ ๋ณดํ†ต ๋ฐ์ดํƒ€ ๋ฒ ์ด์Šค ์ปค๋„ฅ์…˜์„ ๋งบ๊ณ  ํŒŒ์ผ์„ ์—ด๊ณ  ๋ฃฉ์—… ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์„ ์ฒ˜๋ฆฌํ•œ๋‹ค๊ณ  ํ•˜๋„ค์š”.  

JSP Execution ( ์‹คํ–‰ )

๋ธŒ๋ผ์šฐ์ €๊ฐ€ JSP ํŽ˜์ด์ง€๋ฅผ ์š”์ฒญํ•˜๊ณ  ํŽ˜์ด์ง€๊ฐ€ ๋กœ๋“œ๋˜๊ณ  ์ดˆ๊ธฐํ™”๊ฐ€ ๋๋‹ค๋ฉด JSP engine์€ _jspService() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 _jspService() ๋ฉ”์†Œ๋“œ๋Š” HttpServletRequest์™€ HttpServletResponse ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.

void _jspService(HttpServletRequest request, HttpServletResponse response) { // Service handling code... }

JSP์˜ _jspService()๋ฉ”์†Œ๋“œ๋Š” ์š”์ฒญ์ด ์˜ฌ๋•Œ๋งˆ๋‹ค ํ•œ๋ฒˆ์”ฉ ์‹คํ–‰์ด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ์ƒ์„ฑํ•˜๋ฉฐ ๋ชจ๋“  ์ข…๋ฅ˜์˜ HttpRequest๋ฐฉ๋ฒ• ( ie. GET, POST, DELETE, PUT, etc.) ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. 

JSP Cleanup ( ๋’ท์ •๋ฆฌ )

 jspDestroy() ๋ฉ”์†Œ๋“œ๋Š” ์„œ๋ธ”๋ฆฟ์„ ์†Œ๋ฉธ์‹œํ‚ค๋Š” ๋ฉ”์†Œ๋“œ์™€ ๋™์ผํ•œ ๊ฐœ๋…์ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œํ•ด์„œ ํ•„์š”ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํƒ€ ๋ฒ ์ด์Šค ์ปค๋„ฅ์…˜์„ ๋Š๋Š”๋‹ค๋˜์ง€ ํŒŒ์ผ์„ ๋‹ซ๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ์ผ๋“ค์„ ๋ง์ด์ฃ .

 

 jspDestroy() ๋ฉ”์†Œ๋“œ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค.

public void jspDestroy() { // Your cleanup code goes here. }

 

 

Reference : http://www.tutorialspoint.com/jsp/jsp_life_cycle.htm