Servlet

박종원·2024년 9월 29일

Was

  • WAS(Web Application Server)는 웹 서버와 애플리케이션 서버의 기능을 결합한 서버로, 웹 요청을 처리하고 동적 웹 콘텐츠를 생성하는 역할.

Servlet

  • servle + Applet 합성어
  • Java 언어로 작성된 Web Application의 서버측 프로그램

Servlet 등록방법

  1. Web.xml
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>ExampleServlet</servlet-name>
        <servlet-class>com.example.ExampleServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ExampleServlet</servlet-name>
        <url-pattern>/example</url-pattern>
    </servlet-mapping>

</web-app>
  1. 어노테이션

    @webServlet("/MyServlet")

생명주기

  • Servlet 인스턴스는 웹컨테이너에 의해 제어
  • Servlet 인스턴스가 존재하지 않으면 아래의 작업을 수행
    1. Servlet 클래스 로드
    1. Servlet 클래스 인스턴스 생성
    2. Servlet 인스턴스 초기화
    3. 웹 컨테이너에 의한 서비스 메서드 호출
    4. destory 메서드를 호출하여 Servlet 종료

URI : 통합 자원 식별자, 인터넷 상의 자원을 식별하는데 사용
URL : 통합 자원 위치, 자원의 위치를 나타내는데 사용
URN : 통합 자원 이름, 자원에 대한 고유한 이름을 제공

0개의 댓글