본문 바로가기

Programing/JSP

JSP - JSP입문

사용자 삽입 이미지

 

JSP생명주기는 Servlet의 생명주기와 비슷한 생명주기를 가지고 있다.

Servletinit(),service(),destroy()메서드로 이루어져 있지만
JSP는 비슷한 jspInit(),jspService(),jspDestroy()로 이루어진다.


자바 파일과 클래스 파일이 생성되는 곳


%CATALINA_HOME%\work\Catalina\localhost\




간단한 JSP문법



사용자 삽입 이미지











지시문(Directive)작성


* JSP 페이지에 설정 정보를 지정한다.
* page 지시문
(현재페이지가 어떤 마임타입이고 인코딩정보 및 임포트정보)
 <%@page contentType="text/html;charset=EUC-KR"%>




선언문


* 맴버를 정의하는 부분이다.


<%!
 Calendar now;

 public String getString(int n){
  return String.valueOf(n);
 }
%>

  

 

스크립트릿(Scriptlet)작성

 

* 자바 코드를 작성하는 부분이다.


<%
 now = Calendar.getInstance();
 int yy = now.get(Calendar.YEAR);
 int mm = now.get(Calendar.MONTH)+1;
 int dd = now.get(Calendar.DAY_OF_MONTH);
 
 String date = getString(yy) + "-" + getString(mm) + "-" + getString(dd);
%>

 


표현식(Expression)작성

 

* 데이터를 출력하는 부분이다.


<body>
 현재날짜 : <font color="blue"><b><%=date %></b></font>
</body>

 




사용자 삽입 이미지







Tomcat 으로 인하여 자동 생성된 자바 파일을 보면 JSP페이지가 어떻게 자바 파일로 만들어
져 있는지 알수있다.
JSPrequest,response,pageContext,application,config,session,out등등의

내장객체 만들어져 있어 그냥 사용하면된다.


                  ........................앞부분 생략.........................


  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=EUC-KR");
      pageContext = _jspxFactory.getPageContext(this, request, response,
         null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();

 

'Programing > JSP' 카테고리의 다른 글

JSP - page, session, application 간의 차이  (0) 2008.07.29
JSP - Bean활용  (0) 2008.07.29
JSP - forward  (2) 2008.07.29
JSP - include  (0) 2008.07.29
JSP - 간단 HTML과 JSP  (0) 2008.07.29