5.HTTP 요청 및 응답 처리
1. 서블릿의 HTTP 요청 처리
Servlet에서 HTTP 요청과 응답을 실제로 처리하는 역할은 HttpServletRequest 객체와 HttpServletResponse 객체가 담당함
HttpServletRequest 인터페이스
Extends the
ServletRequestinterface to provide request information for HTTP servlets. The servlet container creates anHttpServletRequestobject and passes it as an argument to the servlet’s service methods (doGet,doPost, etc).
개요
javax.servlet.http 패키지에 속한 인터페이스,
서블릿 컨테이너는 HttpServletRequest 객체를 생성 후 해당 객체를 protected service()의 인수로 전달함
정리하면 HttpServletRequest는 HTTP 요청 처리 담당 객체로,
네트워크를 통해 전송되는 HTTP 요청 메시지에 포함된 정보들을 추상화한 클래스
개발자는 클라이언트의
HTTP요청 정보를 처리하기 위해 해당 클래스를 활용하면 됨
2. 서블릿의 HTTP 응답 처리
HttpServletResponse
Extends the
ServletResponseinterface to provide HTTP-specific functionality in sending a response. For example, it has methods to access HTTP headers and cookies. The servlet container creates anHttpServletResponseobject and passes it as an argument to the servlet’s service methods (doGet,doPost, etc).
개요
HTTP 응답 처리 담당 객체,
네트워크를 통해 클라이언트로 응답되는 HTTP 응답 메시지에 포함할 정보들을 추상화한 클래스
개발자는 클라이언트에게 응답할
HTTP응답 메시지를 전송하기 위해 해당 클래스를 활용하면 됨
tomcat 폴더 내 lib/servlet-api.jar 압축 해제
"jar xvf servlet-api.jar"HttpServletRequest, HttpServletResponse 객체 소스 코드 Github