- redirect: 브라우저가 요청. redirect 되는 jsp 페이지도 request 객체 할당
- forward : 서버내부에서 페이지이동.forward 페이지의 request 객체를
forward 되는 페이지로 전달함.
=> 같은 request 영역의 페이지

📌
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- /jsp1/src/main/webapp/chap4/exam.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>여행지 정보</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String local = request.getParameter("local");
/*
exam.jsp 페이지와 exam_seoul.jsp 페이지는 같은 request 영역이 아님
=> request 객체를 공유하지 못함.
request 객체를 공유해야 하는 경우 redirect 는 안됨.
forward 방식을 사용해야함.
*/
// response.sendRedirect("exam_"+local+".jsp");
pageContext.forward("exam_"+local+".jsp");
%>
</body>
</html>
<!DOCTYPE html>
<!--/jsp1/src/main/webapp/chap4/examform.html -->
<html>
<head>
<meta charset="UTF-8">
<title>연습문제</title>
</head>
<body>
<form action="exam.jsp" method="post">
<h3>여행 정보 검색</h3>
<select name="local">
<option value="seoul">서울</option>
<option value="pusan">부산</option>
<option value="daejun">대전</option>
</select><br>
<input type="text" name="name">
<input type="submit" value="검색">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- /jsp1/src/main/webapp/chap4/exam_seoul.jsp--%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>서울 여행 정보</title>
</head>
<body>
<h1>서울 여행 정보 보기</h1>
<h3>서울은 대한민국의 수도다.</h3>
<h3>검색자 : <%=request.getParameter("name") %></h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%--/jsp1/src/main/webapp/chap4/exam_daejun.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>대전 여행 정보</title>
</head>
<body>
<h1>대전 여행 정보 보기</h1>
<h3>대전은 충정도의 중앙에 있는 광역시이다. 경부선과 호남선이 갈리는 곳이다.</h3>
<h3>검색자 : <%=request.getParameter("name") %></h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- /jsp1/src/main/webapp/chap4/exam_pusan.jsp --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>부산 여행 정보</title>
</head>
<body>
<h1>부산 여행 정보 보기</h1>
<h3>부산은 대한민국 제2의 수도이자 제1의 무역항이다. </h3>
<h3>검색자 : <%=request.getParameter("name") %></h3>
</body>
</html>
'수업(국비지원) > JSP' 카테고리의 다른 글
| [JSP] EL(표현식),JSTL - EL에서 연산자 사용 (0) | 2023.04.18 |
|---|---|
| [JSP] EL(표현식),JSTL - EL(Expression Language) 표현언어 (0) | 2023.04.18 |
| [JSP] 내장 객체 - application 기본 객체: 초기화 파라미터, error 에러처리 (0) | 2023.04.18 |
| [JSP] 내장 객체 - session 내장 객체, session 예제 - 장바구니 (0) | 2023.04.18 |
| [JSP] 내장 객체 - 영역 담당 객체: PageContext 객체 (0) | 2023.04.18 |