본문 바로가기
Java/Jservlet, JPA

[Servlet, JPA] Servlet-Mapping

by Chaedie 2022. 5. 25.
728x90

📌 Reference는 Youtube - NewLecture - Servlet & JPA 입니다.

Servlet-Mapping

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet("/hi")
public class Nana extends HttpServlet {
    
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        out.println("Hello ~ ");
    }
}
  • Web.xml file에서 일일이 해줘야 했던, 매핑이 @WebServlet(”/hi”) 처럼 어노테이션을 남김으로써 매핑이 쉬워졌다.
  • 스프링 강의 때 어노테이션이 이해가 안되어 기술 습득에 마찰력이 강하게 작용했다. 하지만 이 강의를 들으면 스프링을 배우는데 이슈사항이 사라질 것같다.
  • 얼른 Servlet, JPA 완강해야겠다!!!

💡 Mapping이란?

Mapping은 "지금 실행되는 Service Method가 실행되는 url이 어디인지?" 설정해주는 것이다. 여기서 @WebServlet(”/hi”) 라는 어노테이션으로 매핑을 했기 때문에 “localhost:8080/hi” 라는 주소에서 우리가 짠 코드가 실행이 되어 보이는 것이다.

 


 

댓글