JSP Implicit Objects๋Š” Java ๊ฐ์ฒด๋“ค์ž…๋‹ˆ๋‹ค. ๋ช…์‹œ์ ์œผ๋กœ ๊ฐœ๋ฐœ์ž๊ฐ€ ์„ ์–ธํ•˜์ง€ ์•Š์•„๋„ JSP Container์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ฐ์ฒด๋“ค์ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ JSP Implicit Objects ๋ฅผ pre-defined ๋ณ€์ˆ˜๋ผ๊ณ  ํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

 

JSP ๋Š” ์•„ํ™‰๊ฐ€์ง€์˜ Implicit Objects๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ €๋„ ์•„๋Š” ๊ฐ์ฒด๋“ค์ด ๋ˆˆ์— ๋ณด์ด๋„ค์š”.

 

ObjectDescription
requestThis is the HttpServletRequest object associated with the request.
responseThis is the HttpServletResponse object associated with the response to the client.
outThis is the PrintWriter object used to send output to the client.
sessionThis is the HttpSession object associated with the request.
applicationThis is the ServletContext object associated with application context.
configThis is the ServletConfig object associated with the page.
pageContextThis encapsulates use of server-specific features like higher performance JspWriters.
pageThis is simply a synonym for this, and is used to call the methods defined by the translated servlet class.
ExceptionThe Exception object allows the exception data to be accessed by designated JSP.


The request Object:

request ๊ฐ์ฒด๋Š” javax.servlet.http.HttpServletRequest ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ํŽ˜์ด์ง€๋ฅผ ์š”์ฒญํ•  ๋•Œ๋งˆ๋‹ค JSP engine ์ด ํ•ด๋‹น ์š”์ฒญ์— ๋Œ€ํ•œ ์ƒˆ๋กœ์šด request๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. request ๊ฐ์ฒด๋Š” HTTP header ์ •๋ณด๋ฅผ ์–ป์–ด์˜ค๊ธฐ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. form data, cookies, HTTP methods๊ฐ™์€ ์ •๋ณด๋“ค์ด ํ—ค๋”์ •๋ณด์— ์žˆ๊ฒ ์ฃ .

request ๊ฐ์ฒด์™€ ๊ด€๋ จ๋œ ๋ฉ”์†Œ๋“œ๋“ค์— ๋Œ€ํ•œ ์ •๋ณด ๋ฐ ์‚ฌ์šฉ๋ฒ•์€ ์˜ค๋ฅธ์ชฝ ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  JSP - Client Request.


The response Object:

response ๊ฐ์ฒด๋Š” javax.servlet.http.HttpServletResponse ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค. ์„œ๋ฒ„๊ฐ€ request ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ, ํด๋ผ์ด์–ธํŠธ๋กœ ๋ณด๋‚ด๊ธฐ์œ„ํ•œ response ๊ฐ์ฒด๋„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

response ๊ฐ์ฒด๋Š” ๋˜ํ•œ ์ƒˆ๋กœ์šด HTTPํ—ค๋” ์ƒ์„ฑ์„ ๋‹ค๋ฃจ๊ธฐ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด์„œ JSP ๊ฐœ๋ฐœ์ž๋“ค์€ ์ฟ ํ‚ค, ๋‚ ์งœ ์Šคํƒฌํ”„,  HTTP ์ƒํƒœ ์ฝ”๋“œ๋“ฑ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

response ๊ฐ์ฒด์™€ ๊ด€๋ จ๋œ ๋ฉ”์†Œ๋“œ๋“ค์— ๋Œ€ํ•œ ์ •๋ณด ๋ฐ ์‚ฌ์šฉ๋ฒ•์€ ์šฐ์ธก ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  JSP - Server Response.


The out Object:

out ๊ฐ์ฒด๋Š” javax.servlet.jsp.JspWriter ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค์ด๋ฉฐ content๋ฅผ response์•ˆ์— ๋ณด๋‚ด๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ฒ˜์Œ์˜ JspWriter ๊ฐ์ฒด๋Š” ํŽ˜์ด์ง€์˜ ๋ฒ„ํผ ์‚ฌ์šฉ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ์ดˆ๊ธฐํ™”๋ฉ๋‹ˆ๋‹ค.  Buffering ๊ธฐ๋Šฅ์€ page ๋””๋ ‰ํ‹ฐ๋ธŒ์˜ buffered='false' ์†์„ฑ์„ ํ†ตํ•ด์„œ ์‰ฝ๊ฒŒ off ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. JspWriter ๊ฐ์ฒด๋Š” java.io.PrintWriter ํด๋ž˜์Šค์™€ ๊ฑฐ์˜ ๋™์ผํ•œ ๋ฉ”์†Œ๋“œ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ JspWriter๋Š” ์ถ”๊ฐ€์ ์œผ๋กœ ๋ฒ„ํผ๋ง์„ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. PrintWriter ๊ฐ์ฒด์™€๋Š” ๋‹ค๋ฅด๊ฒŒ JspWriter ๋Š” IOExceptions์„ ๋˜์ง‘๋‹ˆ๋‹ค.

 

 boolean, char, int, double, object, String, etc. ์„ ์“ฐ๊ณ ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

MethodDescription
out.print(dataType dt)Print a data type value
out.println(dataType dt)Print a data type value then terminate the line with new line character.
out.flush()Flush the stream.


The session Object:

session๊ฐ์ฒด๋Š” javax.servlet.http.HttpSession์˜ ์ธ์Šคํ„ด์Šค์ฃ .  Java Servlets์˜ ์„ธ์…˜๊ณผ ๋™์ผํ•œ ์—ญํ• ์„ ํ•œ๋‹ค๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

session ๊ฐ์ฒด๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์—ฌ๋Ÿฌ๋ฒˆ ์š”์ฒญ์„ ํ•˜๊ฒŒ ๋  ๋•Œ ๊ทธ ์š”์ฒญ๋“ค ์‚ฌ์ด์— ์„ธ์…˜์„ ์ถ”์  ๋ฐ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.  

session ๊ฐ์ฒด์˜ ์‚ฌ์šฉ๋ฒ•์€ ์šฐ์ธก ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  JSP - Session Tracking.


The application Object:

application ๊ฐ์ฒด๋Š” ServletContext๊ฐ์ฒด์˜ wrapper๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ๋Š” javax.servlet.ServletContext ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

 ์ด ๊ฐ์ฒด๋Š” JSP page ์ƒ๋ช…์ฃผ๊ธฐ ์ „์ฒด๋ฅผ ๋Œ€ํ‘œํ•œ๋‹ค๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ข…๋ฃŒ๋˜๊ธฐ ์ „๊นŒ์ง€ ์‚ด์•„์žˆ๋Š” ๊ฐ์ฒด์ฃ . JSP ํŽ˜์ด์ง€๊ฐ€ ์ดˆ๊ธฐํ™”๋  ๋•Œ ์ƒ์„ฑ๋˜๊ณ   jspDestroy()๋ฉ”์†Œ๋“œ์— ์˜ํ•ด JSPํŽ˜์ด์ง€๊ฐ€ ์†Œ๋ฉธ๋  ๋•Œ ์ด ๊ฐ์ฒด๋„ ์†Œ๋ฉธ๋ฉ๋‹ˆ๋‹ค.

 application ๊ฐ์ฒด์— ์†์„ฑ์„ ์ถ”๊ฐ€ํ•จ์œผ๋กœ์จ ํ•ด๋‹น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ชจ๋“  JSP ํŒŒ์ผ๋“ค์ด ์ด๊ณณ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์ƒ๊ธฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Application ๊ฐ์ฒด์˜ ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ๋ฒ•์€ ์šฐ์ธก ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  JSP - Hits Counter


The config Object:

config ๊ฐ์ฒด๋Š” javax.servlet.ServletConfig ์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.  

์ด ๊ฐ์ฒด๋Š” JSP ๊ฐœ๋ฐœ์ž๊ฐ€ Servlet ์ด๋‚˜ JSP ์—”์ง„ ์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ ( paths ๋˜๋Š” file ์œ„์น˜ ๋“ฑ )์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.

๋งŽ์ด ์“ฐ์ด์ง€ ์•Š๋Š” ๊ฐ์ฒด์ด๋ฉฐ ์•„๋งˆ ์“ฐ๊ฒŒ ๋œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์“ฐ๋Š” ๊ฒƒ ๋ง๊ณ ๋Š” ์ •๋ง ์“ธ์ผ์ด ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 


config.getServletName();


์ด๊ฑด ์„œ๋ธ”๋ฆฟ๋ช…์„ ์–ป์–ด์˜ค๋Š” ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค. WEB-INF\web.xml ํŒŒ์ผ์˜   <servlet-name> ์š”์†Œ์— ๋“ค์–ด์žˆ๋Š” ์ด๋ฆ„์„ ์–ป์–ด์˜ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. 


The pageContext Object:

pageContext ๊ฐ์ฒด๋Š”  javax.servlet.jsp.PageContext ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.   pageContext ๊ฐ์ฒด๋Š” JSP page ์ „์ฒด๋ฅผ ๋Œ€ํ‘œํ•ฉ๋‹ˆ๋‹ค.

 ์ด ๊ฐ์ฒด๋Š” ํŽ˜์ด์ง€ ์ •๋ณด๋ฅผ ์–ป์–ด์˜ค๊ธฐ ์œ„ํ•œ ์ˆ˜๋‹จ์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.  

์ด ๊ฐ์ฒด๋Š” ๊ฐ ์š”์ฒญ๋งˆ๋‹ค request ์™€ response๊ฐ์ฒด๋กœ์˜ ๋ž˜ํผ๋Ÿฐ์Šค๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. application, config, session, ๊ทธ๋ฆฌ๊ณ  out ๊ฐ์ฒด๋“ค์€ ์ด ๊ฐ์ฒด์˜ ์†์„ฑ์— ์ ‘๊ทผํ•ด์„œ ์–ป์–ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  pageContext ๊ฐ์ฒด๋Š” ๋˜ํ•œ ํ•ด๋‹น JSP page์—์„œ ๋ฐœ์ƒ๋œ directives์˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ( buffering ์ •๋ณด,  errorPageURL, ๊ทธ๋ฆฌ๊ณ  page scope๊ฐ™์€ ์ •๋ณด๋“ค ๋ง์ด์ฃ  ).

 PageContext ํด๋ž˜์Šค๋Š” PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, ๊ทธ๋ฆฌ๊ณ  APPLICATION_SCOPE ํ•„๋“œ๋“ค์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. 40๊ฐœ ์ด์ƒ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๋ฉฐ ๊ทธ ์ค‘ ๋ฐ˜์€ javax.servlet.jsp.JspContext ํด๋ž˜์Šค์—์„œ ์ƒ์†๋ฐ›์€ ๋ฉ”์†Œ๋“œ๋“ค์ž…๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฉ”์†Œ๋“œ ์ค‘ ํ•˜๋‚˜๋Š” removeAttribute์ธ๋ฐ ์ด ๋ฉ”์†Œ๋“œ๋Š”  ํ•˜๋‚˜ ๋˜๋Š” ๋‘๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค. pageContext.removeAttribute ("attrName") ๋Š” ๋ชจ๋“  scope์—์„œ attrName ์†์„ฑ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์— ๋‚˜์˜จ ๋ฌธ์žฅ์€ page scope์—์„œ๋งŒ ํ•ด๋‹น ์†์„ฑ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. 

 

  pageContext.removeAttribute("attrName", PAGE_SCOPE);


pageContext ๊ฐ์ฒด์— ๋Œ€ํ•œ ์‚ฌ์šฉ๋ฒ•์€ ์šฐ์ธก ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. JSP - File Uploading.


The page Object:

์‹ค์ œ ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. JSP page์ „์ฒด๋ฅผ ๋Œ€ํ‘œํ•˜๋Š” ๊ฐ์ฒด๋ผ๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค..

์ด ํŽ˜์ด์ง€ ๊ฐ์ฒด๋Š” ์‹ค์ œ๋กœ ์ž๋ฐ”์—์„œ ๋‚˜์˜ค๋Š” this ๊ฐ์ฒด์˜ ๋™์˜์–ด๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.  


The exception Object:

exception ๊ฐ์ฒด๋Š” wrapper ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ์ด์ „ ํŽ˜์ด์ง€์—์„œ ๋˜์ ธ์ง„ exception์„ ๊ฐ€์ง€๊ณ  ์žˆ์ฃ .  ๋ญ ์ด๊ฑฐ์•ผ ์ž๋ฐ”๋ฅผ ํ•˜์‹  ๋ถ„๋“ค์ด๋ผ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ๊ฐ์ฒด๋ผ๊ณ  ๊ธˆ๋ฐฉ ์•„์‹ค ๊ฒ๋‹ˆ๋‹ค. ๋ญ ๋” ์„ค๋ช…ํ• ๊ฒŒ ์—†๋„ค์š”.

์ด ๊ฐ์ฒด์— ๋Œ€ํ•œ ์‚ฌ์šฉ๋ฒ•์€ ์šฐ์ธก ๋งํฌ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. JSP - Exception Handling.

 

 

 

 

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