Spring - @HttpServletRequest

박민수·2023년 11월 14일
0

Spring

목록 보기
8/46
post-thumbnail

@HttpServletRequest

HttpServletRequest 객체는 클라이언트의 요청 정보들을 편리하게 조회할 수 있는 기능을 제공한다. 서블릿이 클라이언트의 요청 메시지를 파싱하고, 그 결과를 HttpServletRequest 객체에 담아서 제공한다.

HTTP 요청 메시지

START LINE

  • HTTP 메소드
  • URL
  • 쿼리 스트링
  • 스키마, 프로토콜

헤더

  • 헤더 조회

바디

  • form 파라미터 형식 조회
  • message body 데이터 직접 조회

임시 저장소 기능

HttpServletRequest는 HTTP 요청이 끝날 때 까지 유지되는 임시 저장소 기능을 제공한다.

  • 저장 : request.setAttribute(name, value)
  • 조회 : request.getAttribute(name)

세션 관리 기능

HttpServletRequest는 HttpSession을 반환하는 기능을 제공한다.

  • request.getSession(create: true)
    • true인 경우 Session이 존재하면 현재 Session을 반환하고, 존재하지 않으면 새로운 Session을 생성 후 반환한다.
    • false인 경우 Session이 존재하면 현재 Session을 반환하고, 존재하지 않으면 null을 반환한다.

쿼리 파라미터 조회 메서드

String username = request.getParameter("username"); //단일 파라미터 조회
Enumeration<String> parameterNames = request.getParameterNames(); //파라미터 이름들 모두 조회
Map<String, String[]> parameterMap = request.getParameterMap(); //파라미터를 Map 으로 조회
String[] usernames = request.getParameterValues("username"); //복수 파라미터 조회

참조
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-mvc-2

profile
안녕하세요 백엔드 개발자입니다.

0개의 댓글