request 객체 (요청 처리하는 객체)
request 객체는 클라이언트(브라우저)가 보낸 데이터를 서버에서 받을 때 씀.
예를 들어, 로그인 폼에서 아이디/비밀번호 입력하면 request 객체가 그걸 받아옴.
| 메서드 | 설명 |
|---|---|
getParameter("name") |
폼에서 보낸 name 값 가져옴 (단일 값) |
getParameterValues("hobby") |
체크박스처럼 여러 값을 배열로 가져옴 |
getMethod() |
요청 방식(GET, POST) 확인 |
getCookies() |
요청에 포함된 쿠키 가져오기 |
getSession() |
현재 사용자 세션 가져오기 |
getRemoteAddr() |
클라이언트 IP 주소 가져오기 |
setCharacterEncoding("UTF-8") |
문자 인코딩 설정 (한글 깨짐 방지) |
uid=user123 입력 후 "로그인" 버튼 클릭http://example.com/login.jsp?uid=user123&pass=1234request 객체가 요청 데이터 받음
String uid = request.getParameter("uid"); // "user123"user123이 있는지 확인session 객체 사용해 정보 저장response.sendRedirect("welcome.jsp");response.sendRedirect("login.jsp?error=1");welcome.jsp로 이동login.jsp?error=1로 이동하여 "로그인 실패" 메시지 표시정리
1️⃣ 클라이언트(브라우저) → 폼 입력 & 요청(Request) 전송
2️⃣ 서버(JSP) → request 객체가 요청 데이터 받음
3️⃣ 서버(DB & 비즈니스 로직 실행) → 로그인 정보 확인, 데이터 처리