Open changju opened 2 years ago
public class Application {
public static void main(String[] args) throws LifecycleException {
//스프링 부트를 사용하지 않고 컨테이너 띄우기
// ServletWebServerFactoryAutoConfiguration 에서 자동으로 container 를 설정하게 되어있다.
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
Context context = tomcat.addContext("/", "/");
HttpServlet servlet = new HttpServlet() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter write = resp.getWriter();
write.println("<html><head><title>");
write.println("hey tomcat");
write.println("</title></head>");
write.println("<body><h2> hello tomcat");
write.println("</h2></body>");
write.println("</html>");
}
};
String servletName = "helloServlet";
tomcat.addServlet("/", servletName, servlet);
context.addServletMappingDecoded("/hello", servletName);
tomcat.start();
tomcat.getServer().await();
}
}