You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!DOCTYPE html><html><head><metacharset="UTF-8"><title>Title</title></head><body><ul><li>hello 서블릿
<ul><li><ahref="/hello?username=servlet">hello 서블릿 호출</a></li></ul></li><li>HttpServletRequest
<ul><li><ahref="/request-header">기본 사용법, Header 조회</a></li><li>HTTP 요청 메시지 바디 조회
<ul><li><ahref="/request-param?username=hello&age=20">GET - 쿼리
파라미터</a></li><li><ahref="/basic/hello-form.html">POST - HTML Form</a></li><li>HTTP API - MessageBody -> Postman 테스트</li></ul></li></ul></li><li>HttpServletResponse
<ul><li><ahref="/response-header">기본 사용법, Header 조회</a></li><li>HTTP 응답 메시지 바디 조회
<ul><li><ahref="/response-html">HTML 응답</a></li><li><ahref="/response-json">HTTP API JSON 응답</a></li></ul></li></ul></li></ul></body></html>
✏️ HttpServletRequest - 개요
🔍 HttpServletRequest 역할
서블릿은 개발자가 HTTP 요청 메시지를 편리하게 사용할 수 있도록 개발자 대신에 HTTP 요청 메시지를 파싱한다. 그리고 그 결과를 HttpServletRequest 객체에 담아서 제공한다.
HTTP 요청 메시지
START LINE
HTTP 메소드, URL, 쿼리 스트링, 스키마, 프로토콜
헤더
헤더 조회
바디
form 파라미터 형식 조회, message body 데이터 직접 조회
임시 저장소 기능 (해당 HTTP 요청이 시작부터 끝날 때까지 유지되는 임시 저장소 기능)
저장 : request.setAttribute(name, value)
조회 : request.getAttribute(name)
세션 관리 기능
`request.getSession(create: true)
⭐ 중요
HttpServletRequest, HttpServletResponse를 사용할 때, 이 객체들이 HTTP 요청 메시지, 응답 메시지를 편리하게 사용하도록 도와주는 객체이다. 따라서 이 기능들에 대한 깊이 있는 이해를 하려면 HTTP 스펙이 제공하는 요청, 응답 메시지 자체를 이해해야 한다
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
✏️ 프로젝트 생성
✏️ Hello 서블릿
🔍 스프링 부트 서블릿 환경 구성
@ServletComponentScan을 지원한다.hello.servlet.ServletApplicationhello.servlet.basic.HelloServlet서블릿이름이랑, URL매핑은 겹치면 안된다.
HTTP 요청을 통해 매핑된 URL이 호출되면 서블릿 컨테이너는 다음 메서드를 실행한다.
protected void service (HttpServletRequest request, HttpServletResponse response)웹 브라우저 실행
콘솔 실행 결과

🔍 HTTP 요청 메시지 로그로 확인하기
application.properties에서logging.level.org.apache.coyote.http11=trace추가하기📍 참고!
🔍 서블릿 컨테이너 동작 방식 설명
🔍 welcome 페이지 추가
webapp경로에index.html을 두면 http://localhost:8080 호출 시,index.html페이지가 열린다.main/webapp/index.htmlmain/webapp/basic.html✏️ HttpServletRequest - 개요
🔍 HttpServletRequest 역할
request.setAttribute(name, value)request.getAttribute(name)⭐ 중요
✏️ HttpServletRequest - 기본 사용법
hello.servlet.basic.request.RequestHeaderServlet웹 브라우저에

http://localhost:8080/request-header?username=hello라고 입력했을 때헤더정보
✏️ HTTP 요청 데이터 - 개요
주로 3가지 방법을 사용한다.
1️⃣ GET - 쿼리 파라미터
2️⃣ POST - HTML Form
3️⃣ HTTP message body 에 데이터를 직접 담아서 요청
데이터 형식은 주로 JSON 사용
POST- HTML Form 예시

🔗출처
All reactions