2013년 9월 29일 일요일

[자바JSP서블릿>JSP 스크립틀릿(scriptlet), <% ... %> 요청처리시점에 처리될 하나의 자바코드 블록

[자바JSP서블릿>JSP 스크립틀릿(scriptlet), <% ... %>   요청처리시점에 처리될 하나의 자바코드 블록

 
요청처리시점에 처리될 하나의 자바코드 블록,<% 와 %>로 둘러 쌓인다.

여러 개의 스크립틀릿은 JSP Page안에 나타나는 순서대로 그대로 컴파일된 클래스 안에 삽입된다.

서블릿으로 보면 service() 메소드 안에서 수행되는 코드의 블록들이라고 할 수 있다.

JSP Page가 요청 될 때 마다 수행된다.

[예제]
<%-- scriptlet.jsp --%>
<%@ page contentType="text/html; charset=euc-kr" %>
<html>
<body>
<h1> 스크립틀릿 예제</h1>
<%
   int sum=0;
   for (int i=0;i<5;i++) {
     sum += i;
     out.println("<b>Loop Test...." + i + "</b><br>" );   
   }
   out.println("<b>sum = " + sum);   
%>
</body>
</html>
 
서블릿으로 컴파일된 이후의 파일
// Generated by JRun, do not edit
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import allaire.jrun.jsp.JRunJSPStaticHelpers;
public class jrun__jsp__scriptlet2ejsp12 extends allaire.jrun.jsp.HttpJSPServlet implements allaire.jrun.jsp.JRunJspPage

    private ServletConfig config;
    private ServletContext application;  
    private Object page = this;
    private JspFactory __jspFactory = JspFactory.getDefaultFactory();
    public void _jspService(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, java.io.IOException
    {
        if(config == null) {
            config = getServletConfig();
            application = config.getServletContext();
        }
         response.setContentType("text/html; charset=euc-kr");
         PageContext pageContext = __jspFactory.getPageContext(this, request, response,  null, true, 8192, true);
        JspWriter out = pageContext.getOut();
        HttpSession session = pageContext.getSession();
 int sum = 0;
        try {
    out.print("\r\n<html>\r\n<body>\r\n<h1> \uc774\uac74 \uc2a4\ud06c\ub9bd\ud2c0\ub9bf \uc608\uc81c\uc785\ub2c8\ub2e4. </h1>\r\n");
      for (int i=0;i<5;i++) {
         sum += i;
         out.println("<b>Loop Test...." + i + "</b><br>" );   
       }
       out.println("<b>sum = " + sum);
      out.print("\r\n</body>\r\n</html>\r\n");
       } catch(Throwable t) {
            if(t instanceof ServletException)
                throw (ServletException) t;
            if(t instanceof java.io.IOException)
                throw (java.io.IOException) t;
            if(t instanceof RuntimeException)
                throw (RuntimeException) t;
            throw JRunJSPStaticHelpers.handleException(t, pageContext);   
        }
finally {
            __jspFactory.releasePageContext(pageContext);
        }
   }
     private static final String[] __dependencies__ = {"/jsp/scriptlet.jsp",null};
    private static final long[] __times__ = {984926063107L,0L};
    public String[] __getDependencies()
    {
        return __dependencies__;
    }
    public long[] __getLastModifiedTimes()
    {
        return __times__;
    }
    public int __getTranslationVersion()
    {
        return 13;
    }
}

[개강안내]오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)


오라클자바커뮤니티에서 설립한 개발자교육6년차 오엔제이프로그래밍 실무교육센터
(오라클SQL,튜닝,힌트,자바프레임워크,안드로이드,아이폰,닷넷 실무개발강의)  


댓글 없음:

댓글 쓰기