
HttpServletResponse - 기본 사용법 1. ResponseHeaderServlet (1) @WebServlet(name = "responseHeaderServlet", urlPatterns = "/response-header") public class ResponseHeaderServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //[status-line] response.setStatus(HttpServletResponse.SC_OK); // 200 //[re..

API 메시지 바디 - JSON JSON 형식 전송 JSON 형식 파싱 추가 HelloData @Getter @Setter public class HelloData { private String username; private int age; } Jackson 라이브러리 사용 ObjectMapper @WebServlet(name = "requestBodyJsonServlet", urlPatterns = "/request-body-json") public class RequestBodyJsonServlet extends HttpServlet { private ObjectMapper objectMapper = new ObjectMapper(); @Override protected void service(Ht..

HTTP 요청 데이터 - API Message Body - 단순 텍스트 HTTP message body에 데이터를 직접 담아서 요청 HTTP API에서 주로 사용, JSON, XML, TEXT 데이터 형식은 주로 JSON 사용 - 예전에는 XML이 많이 쓰였다가 지금은 대부분 JSON 사용. 사용 메서드 : POST, PUT, PATCH HTTP 메시지 바디의 데이터를 InpusStream을 사용해서 직접 읽을 수 있다. 이런 API들은 서버와 서버가 통신할 때, 앱에서 서버로 요청할 때 웹 클라이언트에서 자바스크립트로 요청할 때 주로 사용한다. RequestBodyStringServlet @WebServlet(name = "requestBodyStringServlet", urlPatterns = "/r..

HTTP 요청 데이터 - POST HTML Form 주로 회원 가입, 상품 주문 등에서 사용하는 방식 특징 content-type: application/x-www-form-urlencoded 메시지 바디에 쿼리 파리미터 형식으로 데이터를 전달한다. username=hello&age=20 src/main/webapp/basic/hello-form.html username: age: 전송 실행해보기. http://localhost:8080/basic/hello-form.html POST의 HTML Form을 전송하면 웹 브라우저는 다음 형식으로 HTTP 메시지를 만든다. (웹 브라우저 개발자 모드 확인) 요청 URL: http://localhost:8080/request-param content-type:..

HTTP 요청 데이터 - 개요 주로 다음 3가지 방법을 사용한다. GET - 쿼리 파라미터 /url?username=hello&age=20 - 메시지 바디 없이, URL의 쿼리 파라미터에 데이터를 포함해서 전달 예) 검색, 필터, 페이징등에서 많이 사용하는 방식 POST - HTML Form content-type: application/x-www-form-urlencoded - 메시지 바디에 쿼리 파리미터 형식으로 전달 username=hello&age=20 예) 회원 가입, 상품 주문, HTML Form 사용 HTTP message body에 데이터를 직접 담아서 요청 - HTTP API에서 주로 사용, JSON, XML, TEXT 데이터 형식은 주로 JSON 사용 POST, PUT, PATCH PO..

HttpServletRequest 역할 HTTP 요청 메시지를 개발자가 직접 파싱해서 사용해도 되지만, 매우 불편. 서블릿은 개발자가 HTTP 요청 메시지를 편리하게 사용할 수 있도록 개발자 대신에 HTTP 요청 메시지를 파싱한다. 그리고 그 결과를 HttpServletRequest 객체에 담아서 제공한다. HttpServletRequest를 사용하면 다음과 같은 HTTP 요청 메시지를 편리하게 조회할 수 있다. 중요 HttpServletRequest - 기본 사용법 - HttpServletRequest가 제공하는 기본 사용법 알아보기 RequestHeaderServlet -1 @WebServlet(name = "requestHeaderServlet", urlPatterns = "/request-head..

Reference - 인프런 김영한 프로젝트 세팅 Gradle - groovy 프로젝트, Dependencies - Lombok - Spring Web Jar 대신에 War 사용 -> JSP 사용해야 하기 때문에. Postman 사용 - 설치 코드 및 부연 설명 ServletApplication @ServletComponentScan //서블릿 자동 등록 @SpringBootApplication public class ServletApplication { public static void main(String[] args) { SpringApplication.run(ServletApplication.class, args); } } - 내 패키지 포함 하위 패키지 전부 뒤져서 서블릿을 다 찾아낸 다음 등록..