[JSP/Servlet] ์ƒํƒœ ์ •๋ณด Scope

์ƒํƒœ ์ •๋ณด Scope

Servelt๊ณผ JSP๋Š” ๋„ค ๊ฐ€์ง€์˜ ๋ฒ”์œ„(Application > Session > Request > Page)์—์„œ ์ƒํƒœ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ์‚ฌ์šฉํ•œ๋‹ค.

  • ๊ตฌ์„ฑ

๊ณตํ†ต ํŠน์„ฑ

  • setAttribue("์ž๋ฃŒ ์ด๋ฆ„", ์ž๋ฃŒ)๋กœ ๋ณ€์ˆ˜๋ฅผ ์ €์žฅํ•˜๊ณ , getAttribute(์ž๋ฃŒ ์ด๋ฆ„)์œผ๋กœ ๋ณ€์ˆ˜๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.

Page Scope

  • ํ•œ ํŽ˜์ด์ง€ ๋‚ด์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • forwarding์„ ์ด์šฉํ•ด์„œ ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋กœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์—†๋‹ค.
  • ์ง€์—ญ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • JSP์—์„œ๋Š” pageContext ๋‚ด์žฅ ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

Request Scope

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ณด๋‚ธ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต๊นŒ์ง€ ์œ ์ง€๋œ๋‹ค.
  • Servlet์—์„  HttpServletRequest ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.
  • JSP์—์„  request ๋‚ด์žฅ ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค.
  • Request Scope ์ƒํƒœ ์ •๋ณด๋ฅผ ์œ ์ง€ํ•œ ์ฑ„๋กœ ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋กœ ์ „๋‹ฌํ•  ๋•Œ forward๋ฅผ ์ด์šฉํ•œ๋‹ค.

Session Scope

  • ํด๋ผ์ด์–ธํŠธ๋งˆ๋‹ค ์ƒํƒœ ์ •๋ณด๋ฅผ ์ €์žฅํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
  • Servlet์—์„œ๋Š” HttpSession ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.
  • JSP์—์„œ๋Š” session ๋‚ด์žฅ ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค.

Application Scope

  • ํ•˜๋‚˜์˜ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘๋˜๊ณ  ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ์œ ์ง€๋œ๋‹ค.
  • Servlet์—์„œ๋Š” ServletContext ์ž๋ฃŒํ˜•์˜ getServletContext()๋ฅผ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.
  • JSP์—์„œ๋Š” application ๋‚ด์žฅ ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๋“ค์ด ๊ฐ’์„ ๊ณต์œ ํ•œ๋‹ค.