HttpServletRequest 에서 값 얻기
contentType = application/x-www-form-urlencoded (form데이터)
값을 받는 메소드 3가지
- 아래 메소드 들은 form에서 name으로 정의한 이름으로 parameter를 가지고 옴
- String getParameter(”name”) → 전송받은 값 중 지정한 “name”을 String 값으로 가져옴
- String[] getParameterValues(”name”) → 이름들 중 선택한 값을 가져옴
- getParameterNames() → 전송한 모든 name을 가져옴
HttpServletRequest 에서 requestBody 얻어내기
- HttpServletRequest의 inputStream에서 getAllBytes를 Filter 단에서 해버리면 Controller에서 해당 데이터에 접근이 불가능함
이때 ContentCachingRequestWrapper 클래스를 이용
- chain.doFilter에 ContentCachingRequestWrapper 인스턴스로 request를 넣기
- 그 후 해당 request의 inputStream이 한번 읽혀야 캐싱이 됨
- 캐싱된 데이터를 request instance 에서 계속적으로 얻어낼 수 있음