Java/Servlet

Tomcat의 동작 원리

60jong 2023. 4. 2. 02:52

Velog에서도 포스팅 중입니다:)

 

Tomcat의 동작 원리

Tomcat이란 Servlet Container를 통해 Servlet을 제공하는 WAS (Web Application Server)이다.Servlet Container란 Servlet의 creation / execution / destruction을 관리하는 conta

velog.io

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되어 있는지 확인한다.

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

  1.  
  2. 3-1. load되어 있지 않다면, Serlvet 객체를 생성하고, init() 메서드를 실행한다.
  3. Servlet Container는 새로운 Thread를 생성해 Servlet의 service() 메서드를 실행한다. (HttpServletRequest, HttpServletResponse 객체를 파라미터로 넘김)
  4. 4-1. service() 메서드 내부에서 doGet() or doPost()메서드가 실행된다.
  5. Servlet Container는 응답 결과인 response를 HttpResponse로 변환해 WS로 넘겨주게 된다.
  6. Servlet Container는 HttpServletRequest, HttpServletResponse 객체를 소멸한다.
  7. Thread를 종료한다.

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

'Java > Servlet' 카테고리의 다른 글

Servlet, JSTL  (0) 2023.04.02
Servlet, JSP로 게시판 구현  (0) 2023.04.01
Servlet, JSP에 MVC를  (0) 2023.04.01
Servlet, JSP를 이용한 웹 프로그래밍 (스파게티 코드 문제)  (0) 2023.04.01
Servlet, JSP with Japser  (0) 2023.04.01