2021.08.30 TIL

새롭게 배운 것 Done

운동

독서

알고리즘

코딩

WAS (Web Application Server)

image

Servlet

MVC 패턴

스크린샷, 2021-08-30 19-02-30

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>test</servlet-name>
        <servlet-class>org.prgrms.kdt.servlet.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

톰캣 설치 후 설정

스크린샷, 2021-08-31 17-13-51

@WebServlet(value = "/*", loadOnStartup = 1)

public class KdtWebApplicationInitializer implements WebApplicationInitializer {

    private static final Logger logger = LoggerFactory.getLogger(KdtWebApplicationInitializer.class);

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        logger.info("starting server...");
        var servletRegistration = servletContext.addServlet("test", new TestServlet());
        servletRegistration.addMapping("/*");
        servletRegistration.setLoadOnStartup(1);
    }
}

참고

webserver vs was


깨달은 점 FEELING