Replies: 1 comment 1 reply
|
첫 번째 것도 추가하셨네용 ! 수고하셨습니다 ~ |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
서블릿 2
6️⃣ HTTP 요청 데이터 - GET 쿼리 파라미터
쿼리 파라미터는 보통 검색, 필터, 페이징 등에서 많이 사용되는 방식이다.
퀴리 파라미터는 URL에 다음과 같이
?를 시작으로 보낼 수 있다. 추가 파라미터는&으로 구분하면 된다.쿼리 파라미터 조회는 HttpServletRequest로 조회할 수 있다.
✅ Request 안에 parameter 조회
✅이름이 같은 복수 파라미터가 있을시
7️⃣HTTP 요청 데이터 - POST HTML Form
content-type:
application/x-www-form-urlencoded메시지 바디에 쿼리 파리미터 형식으로 데이터를 전달한다.
username=hello&age=20POST의 HTML Form을 전송하면 웹 브라우저는 다음 형식으로 HTTP 메시지를 만든다. (웹 브라우저 개발자 모드
확인)
8️⃣HTTP 요청 데이터 - API 메시지 바디 - 단순 텍스트
9️⃣HTTP 요청 데이터 - API 메시지 바디 - JSON
JSON 형식 전송
POST http://localhost:8080/request-body-json
content-type: application/json
message body : {"username": "hello", "age": 20}
결과: messageBody = {"username": "hello", "age": 20}
{ "username": "hello", "age": 20 }Postman으로 실행해보자.
{ "username": "hello", "age": 20 }0️⃣HTTP 응답 데이터 - 단순 텍스트, HTML
HTTP 응답 메시지는 아래의 내용을 담아서 전달한다.
단순 텍스트 응답
writer.println(”ok”)HTML 응답
HTTP API - MessageBody JSON 응답
HttpServletResponse - HTML 응답
text/html로 지정해야 한다.1️⃣ 1️⃣HTTP 응답 데이터 - API JSON
HTTP 응답으로 JSON을 반환할 때는 content-type을 application/json 로 지정해야 한다.
Jackson 라이브러리가 제공하는 objectMapper.writeValueAsString() 를 사용하면 객체를 JSON 문자로
변경할 수 있다.
🔗출처
All reactions