WEB Archive
[HTML] 포워딩 실습
universedevelope
2024. 8. 22. 08:24
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send10.jsp</title>
</head>
<body>
<div>
<h1>데이터 송수신 실습10</h1>
<hr>
</div>
<div>
<!-- Send10.jsp → Send10_re.jsp → Receive10.jsp
Send10.jsp → Send10_for.jsp → Receive10.jsp -->
<!-- 사용자 최초 요청 페이지 -->
<!-- http://localhost:8090/WebApp07/Send10.jsp -->
</div>
<div>
<h2>포워딩 및 리다이렉트</h2>
</div>
<div>
<form action="" method="post">
이름<input type="text" name="userName" class="txt">
<br>
<br>
<!-- check~~ -->
<button type="submit" class="btn" style="width: 150px"
onclick="this.form.action='Send10_re.jsp'">리다이렉트</button>
<!-- 1번째 시도 : null / null -->
<button type="submit" class="btn" style="width: 150px"
onclick="this.form.action='Send10_for.jsp'">포워드</button>
<!-- 최초 : null / null -->
</form>
</div>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// 이전 페이지로(Send10.jsp) 부터 데이터 (userName) 수신
// ①
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("userName");
//이페이지에서 수행한 추가 작업
//②
request.setAttribute("message", "안녕하세요.");
//-- request 객체의 key(message)의 값 안에
// "반갑습니다" 를 value 로 넣은 작업 수행
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send10_for.jsp</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div>
<h1>데이터 송수신 실습 10</h1>
<hr>
</div>
<div>
<h2>포워드</h2>
</div>
<div>
<p>이름 : <%=userName %> </p>
</div>
<!-- ※ 포워드 -->
<!-- ③ -->
<jsp:forward page="Receive10.jsp"></jsp:forward>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// 이전 페이지로(Send10_re.jsp 또는 Send10_for.jsp)부터 데이터(userName, message) 수신
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("userName");
// getAttribute("") 가 반환하는 것은 Object(객체임)
// 따라서 String 으로 다운캐스팅 해서 변수에 담자
String message = (String)request.getAttribute("message");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Receive10.jsp</title>
</head>
<body>
<div>
<h1>데이터 송수신 실습 10</h1>
</div>
<div>
<p>이름 : <%=userName %></p>
<p>내용 : <%=message %></p>
</div>
</body>
</html>
728x90