Tomcat의 동작 원리

60jong·2023년 1월 21일
0

Servlet / JSP

목록 보기
17/17
post-thumbnail

Tomcat

Tomcat이란 Servlet Container를 통해 Servlet을 제공하는 WAS (Web Application Server)이다.

Servlet Container

Servlet Container란 Servlet의 creation / execution / destruction을 관리하는 container이다.

Servlet

Servlet이란 WAS위에서 동작하는 JAVA 객체(클래스)이다.

Tomcat의 동작 원리

  1. Tomcat이 WS (Web Server)로 부터 동적 (dynamic) 페이지 요청을 받게 된다.

  2. Servlet Container는 HttpServletRequest와 HttpServletResponse 객체를 생성한다.

  3. Servlet Container의 address space에 요청된 페이지에 해당하는 Servlet이 load되어 있는지 확인한다.

    3-1. load되어 있지 않다면, Serlvet 객체를 생성하고, init() 메서드를 실행한다.

    Servlet은 Servlet Container에 load된 뒤에 바로 소멸하지 않고, 자신에게 들어오는 요청에 계속 응답하게 된다. -> init() 메서드는 Servlet 객체 생성 후 한 번만 실행

  4. Servlet Container는 새로운 Thread를 생성해 Servlet의 service() 메서드를 실행한다. (HttpServletRequest, HttpServletResponse 객체를 파라미터로 넘김)

    4-1. service() 메서드 내부에서 doGet() or doPost()메서드가 실행된다.

  5. Servlet Container는 응답 결과인 response를 HttpResponse로 변환해 WS로 넘겨주게 된다.

  6. Servlet Container는 HttpServletRequest, HttpServletResponse 객체를 소멸한다.

  7. Thread를 종료한다.


위 그림이 과정을 가장 잘 표현한 것 같아서 첨부 했다.

profile
울릉도에 별장 짓고 싶다

0개의 댓글