sessionFormC.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
String objName = (String)session.getAttribute("objName");
String objjobs = (String)session.getAttribute("jobs");
String objhobby = (String)session.getAttribute("one");
%>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>3번째 페이지 session 값 </h1>
<center>
이름 : <%=objName %><br>
직업 : <%=objjobs %><br>
관심분야 :<%=objhobby %><br>
</center>
</body>
</html>
sessionFormA.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>
<script type="text/javascript">
document.cookie = "test=OK."
</script>
</head>
<body>
<center>
<h1>첫번째 페이지</h1>
<form action="requestFormB.jsp" method="post">
<table border="1">
<tr>
<td>이름</td>
<td><input type="text" name="objName"></td>
</tr>
<tr>
<td>직업</td>
<td><select name="jobs">
<option value="super">슈퍼맨</option>
<option value="bet">배트맨</option>
</select></td>
</tr>
<tr>
<td>관심분야</td>
<td><input type="checkbox" name="obhobby" value="ecnomic">정치
<input type="checkbox" name="obhobby" value="social">사회 <input
type="checkbox" name="obhobby" value="elect">정보통신</td>
</tr>
<tr>
<td><input type="submit" value="확인"> <input
type="reset" value="취소"></td>
</tr>
</form>
</center>
<HR>
<!-- ///////////////////////////////////////////////////// -->
</table>
</body>
</html>
sessionFormB.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% request.setCharacterEncoding("UTF-8"); %>
<%
String objName = request.getParameter("objName");
String jobs = request.getParameter("jobs");
String []one = request.getParameterValues("obhobby");
String list = "";
for(String str: one){
list += str;
}
%>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%System.out.println("이름이 담기니?"); %>
<%session.setAttribute("objName", objName); %>
<%System.out.println("직업이 담기니?"); %>
<%session.setAttribute("jobs", jobs); %>
<%System.out.println("관심 분야가 담기니?"); %>
<%session.setAttribute("one", list); %>
<%response.sendRedirect("requestFormC.jsp"); %> <!--값을 넘겨주지않고 페이지만 옮겨준다.-->
<!-- response.sendRedirect("RequestC.jsp?userName="+userName +"&job=" + job + "&hobbies=" + hobbies); -->
</body>
</html>
순서는 A > B > C
출력 값
'Jsp' 카테고리의 다른 글
JSP 에러 페이지를 만들어보자! (0) | 2020.08.26 |
---|---|
JSP forward를 이용하여 값을 넘겨보자! (0) | 2020.08.26 |
JSP get 방식 한글깨짐 및 post 방식 한글깨짐 방지해보자 (0) | 2020.08.26 |
JSP scope 객체 종류 가 무엇이고 어떤 역할을 하는지 알아보자 (0) | 2020.08.26 |
JSP 서블릿을 이용한 계산기 만들기(어노테이션 )2 (0) | 2020.08.25 |