Everything has an expiration date
[JSP & Servlet] 20231212 [프로그램소스] - Send09, Send09_for, Send09_re, Receive09 본문
[JSP & Servlet]/Program source (JSP & Servlet)
[JSP & Servlet] 20231212 [프로그램소스] - Send09, Send09_for, Send09_re, Receive09
Jelly-fish 2023. 12. 12. 15:12
WebApp07
012
Send09.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// 이전 페이지(Send09_re.jsp 또는 Send09_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>Send09.jsp</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div>
<h1>데이터 송수신 실습 09</h1>
<hr>
</div>
<!-- Send09.jsp → Send09_re.jsp → Receive09.jsp -->
<!-- Send09.jsp → Send09_for.jsp → Receive09.jsp -->
<!-- 사용자 최초 요청 페이지 -->
<!-- http://localhost:3306/WebApp07/Send09.jsp -->
<div>
<h2>포워딩 및 리다이렉트</h2>
</div>
<div>
<!-- action 처리에 대한 분기~!!! -->
<form action="" method="post" id="textForm">
이름
<input type="text" name="userName" class="txt">
<br><br>
<button type="submit" class="btn" style="width: 150px"
onclick="this.form.action='Send09_re.jsp'">리다이렉트</button>
<!-- button 객체를 포함하고 있는 textForm의 action(목적지)를 분기. -->
<button type="submit" class="btn" style="width: 150px"
onclick="this.form.action='Send09_for.jsp'">포워드</button>
</form>
</div>
</body>
</html>
Send09_re.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ① 이전 페이지(Send09.jsp) 로부터 넘어온 데이터 수신
// → userName
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("userName");
// ② 이 페이지에서 수행한 추가 작업
request.setAttribute("message", "반갑습니다.");
//-- request 객체의 key(message)의 값 안에
// "반갑습니다." 를 value 로 넣는 작업 수행
//=========================================================================
// Receive09.jsp가 주소창 url에 나타나서
// 클라이언트가 자신에게 서비스를 제공해주는 대상이 누구인지 알 수 있다.
//=========================================================================
// "message" "반갑습니다" → 클라이언트가 입력한 값.
// ※
// ③ 리다이렉트
response.sendRedirect("Receive09.jsp");
// 다시 Receive09.jsp에게 요청하라고 알려주는 것.
// 저는 그 서비스를 제공하지 않으니
// Receive09.jsp 에 찾아가서 다시 요청하세요.
// 새롭게 Receive09.jsp 페이지에 요청을 하게 되면서
// request.setAttribute("message", "반갑습니다."); 사용자가 넘겨준 값 소멸.
// 그 페이지에서 다시 요청해야 함. → null 값이 나온 이유.
//이름 : null
//내용 : null
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send09_re.jsp</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div>
<h1>데이터 송수신 실습 09</h1>
<hr>
</div>
<div>
<h2>리다이렉트</h2>
</div>
<div>
<!-- <p>이름 : 홍길동</p> -->
<p>이름 : <%=userName %></p>
</div>
</body>
</html>
Send09_for.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ① 이전 페이지(Send09.jsp) 로부터 넘어온 데이터 수신
// → userName
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("userName");
// 파란 박스 에 userName 존재.
// ② 이 페이지에서 수행한 추가 작업
request.setAttribute("message", "안녕하세요.");
//-- request 객체의 key(message)의 값 안에
// "안녕하세요." 를 value 로 넣는 작업 수행
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send_for.jsp</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div>
<h1>데이터 송수신 실습 09</h1>
<hr>
</div>
<div>
<h2>포워드</h2>
</div>
<div>
<!-- <p>이름 : 홍길동</p> -->
<p>이름 : <%=userName %></p>
</div>
<!-- ③ 포워드 -->
<jsp:forward page="Receive09.jsp"></jsp:forward>
<!-- jsp: (jsp 액션 태그)
현재 상태에서는 forward를 해 줄 수 있는 태그다. -->
</body>
</html>