¼Ò¼³°°ÀºJSP1ºÎ  3Àå Basic of JSP  07 _jspService ¸Þ¼­µåÀDZ¸Á¶  

07 JSP ³»ºÎ _jspService ¸Þ¼­µåÀDZ¸Á¶

 

±×·³ _jspService()¸Þ¼­µåÀÇ ³»ºÎ¸¦ »ìÆì º¸µµ·Ï ÇϰڽÀ´Ï´Ù. ÀÌ _jspService()¸Þ¼­µå´Â ¸Å°³º¯¼ö·Î request¿Í response¸¦ °®½À´Ï´Ù. request´Â HttpServletRequestÇüÀ» °®À¸¸ç response´Â HttpServletResponseÇüÀ» °®½À´Ï´Ù. ¿ì¼± ¾Õ¿¡¼­ ¾ð±ÞÇßµíÀÌ jspÀÇ <% %>ÀÇ ³»¿ë°ú htmlű׵éÀÌ ÀÌ ¸Þ¼­µå ¾È¿¡ »ðÀԵ˴ϴÙ. ±×¸®°í ¿©·¯ °³ÀÇ Áö¿ª º¯¼öµéÀÌ ¼±¾ðµÇ°í »ç¿ëµË´Ï´Ù. _jspService ÀÇ ±¸¼º¿ä¼Ò¸¦ »ìÆìº¸¸é ´ÙÀ½°ú °°½À´Ï´Ù.

 

_jspServiceÀÇ ±¸¼º

n         ¸Å°³º¯¼ö2°³

1.        HttpServletRequest request

2.        HttpServletResponse response

n         ÇÊ¿äÇÑ Áö¿ªº¯¼ö

1.        PageContext pageContext = null;

2.        HttpSession session = null;

3.        ServletContext application = null;

4.        ServletConfig config = null;

5.        JspWriter out = null;

6.        Object page = this;

7.        JspFactory _jspxFactory = null;

8.        String  _value = null;

n         Áö¿ªº¯¼öÃʱâÈ­

1.        _jspxFactory = JspFactory.getDefaultFactory();

2.        pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);

3.        application = pageContext.getServletContext();

4.        config = pageContext.getServletConfig();

5.        session = pageContext.getSession();

6.        out = pageContext.getOut();

 

 À§ÀÇ ¸ðµç º¯¼öµéÀº Á¦°¢°¢ _jspService³»¿¡ Áß¿äÇÑ ¿ªÇÒÀ» ÇÏ¸ç ¾ÕÀ¸·Îµµ °è¼Ó »ç¿ëµÇ´Â º¯¼öµéÀÔ´Ï´Ù. À§ÀÇ ÃʱâÈ­ µÈ º¯¼ö¿Í ¸Å°³º¯¼öµéÀ» ³»À尴ü¶ó°í ºÎ¸¨´Ï´Ù. ±×·³ _jspService¸Þ¼­µå ºÎºÐÀ» Á÷Á¢ º¸¸é¼­ ¼³¸íÇØ ³ª°¡°Ú½À´Ï´Ù. hello.jsp¿¡ ÇØ´çÇÏ´Â _jspService¸Þ¼­µå ºÎºÐÀº ¾Æ·¡¿Í °°½À´Ï´Ù.

 

hello.jsp

Hello World! JSP¸¦ Å×½ºÆ®Çϱâ À§ÇÑ ¿¹Á¦

<html><head><title>Hello JSP</title></head><body>

<h1> Hello JSP Test</h1>

<%

out.println("<font color=blue>Hello World! JSP</font>");

%>

</body></html>

 

_jspService¸Þ¼­µå ºÎºÐ

  public void _jspService(HttpServletRequest request, HttpServletResponse  response)
        
throws java.io.IOException, ServletException {
        JspFactory _jspxFactory = 
null;
        PageContext pageContext = 
null;
        HttpSession session = 
null;
        ServletContext application = 
null;
        ServletConfig config = 
null;
        JspWriter out = 
null;
        Object page = 
this;
        String  _value = 
null;
        
try {
            
if (_jspx_inited == false) {
                
synchronized (this) {
                    
if (_jspx_inited == false) {
                        _jspx_init();
                        _jspx_inited = 
true;
                    }
                }
            }
            _jspxFactory = JspFactory.getDefaultFactory();
            response.setContentType(
"text/html;charset=ISO-8859-1");
            pageContext = _jspxFactory.getPageContext(this, request, response,
"",true, 8192true);
            application = pageContext.getServletContext();
            config = pageContext.getServletConfig();
            session = pageContext.getSession();
            out = pageContext.getOut();
            
// HTML // begin [file="/hello.jsp";from=(0,0);to=(2,0)]
            
out.write("<html><head><title>Hello JSP</title></head><body>\r\n<h1> Hello JSP Test</h1>\r\n");
            
// end
            // begin [file="/hello.jsp";from=(2,2);to=(4,0)]
                  
out.println("<font color=blue>Hello World! JSP</font>");
            
// end
            // HTML // begin [file="/hello.jsp";from=(4,2);to=(8,0)]
                
out.write("\r\n</body></html>\r\n\r\n\r\n");
            
// end
        
catch (Throwable t) {
            
if (out != null && out.getBufferSize() != 0)
                out.clearBuffer();
            
if (pageContext != null) pageContext.handlePageException(t);
        } 
finally {
            
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
        }
   }

 

 ¿ì¼± ¸Þ¼­µå¸¦ º¸¸é IOException, ServletExceptionÀÌ ¼±¾ðµÇ¾î ÀÖ½À´Ï´Ù. ÀÚµ¿À¸·Î jspÆÄÀÏÀ» ServletÆÄÀÏ·Î ¹Ù²ãÁÖ´Â °ÍÀÎ ¸¸Å­ ÀÚ¼¼È÷ ½Å°æ ¾²Áö ¾Ê¾Æµµ µÇ°ÚÁö¸¸, ÀÌ·¸°Ô Exception ¼±¾ðÀÌ µÇ¾î ÀÖ´Ù´Â Á¤µµ´Â ¾Ë°í ÀÖ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.

 

 ±×¸®°í ¸Þ¼­µå ³»ºÎ¿¡¼­ Áö¿ª º¯¼ö¸¦ ¼±¾ðÇϰí ÀÖ½À´Ï´Ù. ÀÌ ¼±¾ðµÈ °´Ã¼º¯¼ö¸¦ ÃʱâÈ­ ÇÑ ÈÄ _jspService¸Þ¼­µå ³»¿¡¼­ »ç¿ëÇϰí ÀÖ½À´Ï´Ù. Áö¿ª°´Ã¼º¯¼ö¿Í jsp¿¡¼­ »ç¿ëµÇ´Â ű׻çÀÌ¿¡´Â ¹Ì¹¦ÇÑ °ü°è°¡ ÀÖ½À´Ï´Ù.

 

<% %>ÅÂ±×¿Í _jspServiceÀÇ Áö¿ªº¯¼ö

n        jsp¹®¼­ÀÇ <%  %>ÅÂ±× ¾È¿¡ µé¾î ÀÖ´Â ºÎºÐÀº _jspService¸Þ¼­µå¾È¿¡ »ðÀԵȴÙ.

n        <%  %> ³»¿¡¼­ _jspService¸Þ¼­µå ³»ÀÇ Áö¿ªº¯¼ö¸¦ ¸ðµÎ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

 

¿©±â¿¡ ¼±¾ðµÈ pageContext, session, application, config, out, page¿Í ¸Å°³º¯¼ö request, response¸¦ ¿ì¸®´Â ³»À尴ü¶ó ºÎ¸¨´Ï´Ù. <% %>ÅÂ±× ³»¿¡¼­´Â _jspService¿¡ Á¸ÀçÇÏ´Â out°´Ã¼¸¦ ÀÌ¿ëÇÏ¿© Ŭ¶óÀÌ¾ðÆ®·Î printlnÀ» Çϰí ÀÖ½À´Ï´Ù. À̰ÍÀº <% %>ÅÂ±× ³»ÀÇ ¸ðµç ³»¿ëÀÌ _jspService³»ÀÇ Áö¿ªº¯¼ö ¾Æ·¡ ÂÊ¿¡ À§Ä¡Çϱ⠶§¹®¿¡ °¡´ÉÇÑ ÀÏÀÔ´Ï´Ù.

 

JSP ³»À尴ü

ServletRequest request (HttpServletRequest request) : Ŭ¶óÀ̾ðÆ®ÀÇ http¿äûÀ» ´ã°í ÀÖ´Â °´Ã¼

ServletResponse response (HttpServletResponse response) : Ŭ¶óÀÌ¾ðÆ®·Î ÀÀ´äÀ» Àü¼ÛÇÒ °´Ã¼

PageContext pageContext : ´Ù¸¥ ³»À尴ü¸¦ ¾ò°Å³ª, ¿äûÀ» ó¸®ÇÒ Á¦¾î±ÇÀ» ´Ù¸¥ ÆäÀÌÁö·Î À§ÀÓÇÏ´Â °´Ã¼

HttpSession session : Ŭ¶óÀÌ¾ðÆ®¿Í ¼­¹ö¿ÍÀÇ ¼¼¼Çµ¥ÀÌÅ͸¦ °¡Áö°í ÀÖ´Â °´Ã¼

ServletContext application : Web applicationÀÌ ½ÇÇàµÇ´Â ½ÇÇà ȯ°æ¿¡ ´ëÇÑ Á¤º¸¸¦ ´ã°í ÀÖ´Â °´Ã¼

JspWriter out : ServletÀÌ ¿äûÀ» ó¸®ÇÏ¿© ÀÀ´äÀ» Àü¼ÛÇÒ ¶§ Àü¼ÛÇÒ ÀÀ´ä¿¡ ´ëÇÑ Ãâ·Â ½ºÆ®¸² °´Ã¼

ServletConfig config : Servlet °´Ã¼°¡ ÂüÁ¶ÇÏ°Ô µÉ Ãʱ⠼³Á¤ µ¥ÀÌÅÍ¿¡ ´ëÇÑ Á¤º¸¸¦ ´ã°í ÀÖ´Â °´Ã¼

Object page (HttpJspPage) : Servlet °´Ã¼¸¦ ÂüÁ¶ÇÏ´Â ·¹ÆÛ·±½º

Throwable exception : ¿¹¿Ü°¡ ¹ß»ýÇÒ °æ¿ì ¿¡·¯ ÆäÀÌÁö¿¡ Àü´ÞµÇ´Â °´Ã¼



jabookÀúÀÚ¸íÇÔ
Á¦¸ñ:¼Ò¼³°°ÀºJSP1ºÎ
ÀúÀÚ:ÃÖ¿µ°ü