-
servlet life-cyclejsp&servlet 2020. 6. 30. 03:16
servlet lilfe-cycle 생명주기
생명주기 코드로 보기
package com.servlet; import java.io.IOException; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class ServletEx */ @WebServlet("/SE1") public class ServletEx extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//실질적 service부분 // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } @PostConstruct//servlet 생성 준비 public void PostConstruct() { System.out.println("PostConstruct"); } @Override//servlet 생성 public void init() throws ServletException { System.out.println("init"); } @Override//servlet 소멸 public void destroy() { System.out.println("destroy"); } @PreDestroy//servlet 종료 public void preDestroy() { System.out.println("preDestroy"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
로그
정보: 서버가 [361] 밀리초 내에 시작되었습니다.
PostConstruct
init
do get이후 web server가 종료되면
destroy
preDestroy해당 로그가 출력됩니다!
'jsp&servlet' 카테고리의 다른 글
jsp 주요 script (0) 2020.06.30 form 데이터 처리 (0) 2020.06.30 servlet request,response (0) 2020.06.30 servlet mapping (0) 2020.06.30 웹 프로그램 개요 및 jsp기초 (0) 2020.06.29