<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_Test</title>
</head>
<body>
<h3>웹페이지 내부 변수의 scope(유효범위)</h3>
<%-- [페이지이동]
1.<a href=""> </a>
2.<form action=""></form>
3.location.href=""
4.<jsp:forward page=""> </jsp:forward>
※5.response.sendRedirect("")
--%>
<%
pageContext.setAttribute("one", 100);
request.setAttribute("two", 200);
session.setAttribute("three", 300);
application.setAttribute("uid", "itwill");
%>
</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>
<h3>scope 유효범위 결과 </h3>
<%
out.print("1.pageContext영역:"+pageContext.getAttribute("one") +"<hr>");
out.print("2.request영역:"+request.getAttribute("two") +"<hr>");
out.print("3.session영역:"+session.getAttribute("three") +"<hr>");
out.print("4.application영역:"+application.getAttribute("uid") +"<hr>");
%>
</body>
</html>
request.getAttribute("two") null값
<a href="scoperesult_02.jsp"> 결과페이지 이동</a>
request.getAttribute("two") null값 출력
<form action="scoperesult_02.jsp">
<input type="submit" value="[결과페이지]">
</form>
request.getAttribute("two") null값 출력
<script>
alert("결과페이지 이동");
location.href="scoperesult_02.jsp"
</script>
request.getAttribute("two") null값 출력
forward 사용
<jsp:forward page="scoperesult_02.jsp"></jsp:forward>
request값 출력!
request내부 변수는 부모페이지와 자식 페이지에서만 유효하다
<%
response.sendRedirect("scoperesult_02.jsp");
%>
request.getAttribute("two") null값 출력
<%
String view="scoperesult_02.jsp";
RequestDispatcher rd=request.getRequestDispatcher(view);
rd.forward(request, response);
%>
request값 출력!