티스토리 뷰

728x90
<%@ 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>
<%
	// request.setAttribute : 오브젝트를 키워드로 request에 저장시 사용하는 메서드
	// request.getAttribute : 오브젝트에 담긴 데이터를 request로 가져올 때 사용하는 메서드
	
	request.setAttribute("id", "abcd");
	request.setAttribute("pw", "1234");
	
	//값들이 null로 나옴
	//response.sendRedirect("example4_1.jsp");
	//지정값이 정상적으로 나옴
	pageContext.forward("example4_1.jsp");
%>
</body>
</html>
<%@ 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>
<%
	//데이터가 object형으로 오기 때문에 String으로 형변환 필요
	String id = (String)request.getAttribute("id");
	String pw = (String)request.getAttribute("pw");
%>

	<h1>example4.jsp에서 받은 데이터</h1>
	<p>id : <%=id %></p>
	<p>pw : <%=pw %></p>
</body>
</html>

>실행은 example4.jsp에서!!!!

response.sendRedirect("example4_1.jsp");
pageContext.forward("example4_1.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>
<%

	request.setAttribute("id", "abcd");
	request.setAttribute("pw", "1234");

%>
	<jsp:forward page="example5_1.jsp"></jsp:forward>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String id = (String)request.getAttribute("id");
	String pw = (String)request.getAttribute("pw");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>example5_1.jsp 페이지 입니다.</h1>
	<p><%=id %></p>
	<p><%=pw %></p>
</body>
</html>

example5.jsp
example5_1.jsp

728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함