해당 게시글은 모두 인프런 실전 JSP (renew ver.) - 신입 프로그래머를 위한 강좌 https://www.inflearn.com/course/%EC%8B%A4%EC%A0%84-jsp_renew/dashboard에 출처를 두고 있습니다. 간략히 정리한 글 입니다.
init()
: 실행전 초기화하는 단계
service
: 실제로 서비스를 제공하는 메서드, service()
메서드 보단 doGet()
이나 doPost()
로 서비스를 제공합니다.
destroy()
: 종료시 실행
@PostConstruct
, @PreDestroy
: 개발자가 임의로 시작이나 종료시 추가하고 싶은 사항을 추가하는 에노테이션
//servlet실행
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
System.out.println("-- doGet() --");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
@PostConstruct
public void funPc() {
System.out.println("-- postConstruct() --");
}
//서블릿 생성
@Override
public void init() throws ServletException {
System.out.println("-- init() --");
}
//서블릿 종료
@Override
public void destroy() {
System.out.println(" --destroy()--");
}
@PreDestroy
public void FuncPd() {
System.out.println("-- preDestroy() --");
}
생명주기별로 나누어서 개발하면 좀 더 짜임새 있게 개발할 수 있을 것 같다.