< 리다이렉트(redirect) 란? >
- HTTP 프로토콜로 정해진 규칙
- 서버는 클라이언트로부터 요청을 받은 후 클라이언트에게 특정 URL로 이동하라고 요청할 수 있음 -> 이때 status code를 302로 보내고 함께 이동할 URL 정보를 헤더에 담아 response로 전송함
- 클라이언트(브라우저)의 주소창이 전송받은 URL로 변경됨
- 서블릿이나 jsp는 리다이렉트를 하기 위해 sendRedirect() 메소드 사용
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
response.sendRedirect("redirect2.jsp");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
redirect2
</body>
</html>
redirect1.jsp를 톰캣에서 run했을 때
동작 방식
- redirect1.jsp 요청
- redirect2.jsp로 리다이렉트 요청 (status code : 302)
- 웹 브라우저는 WAS의 리다이렉트 요청을 받고 redirect2.jsp 요청
- redirect2.jsp 결과 출력