● [페이지 이동]
1) <a href="?"></a>
2) location.href=""
3) <form action=""></form>
4) <jsp:forward page=""></jsp:forward>
5) response.sendRedirect("")
02_scopeTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_scopeTest.jsp</title>
</head>
<body>
<h3>웹페이지의 SCOPE(유효범위)</h3>
<%--
● [페이지 이동]
1) <a href="?"></a>
2) location.href=""
3) <form action=""></form>
4) <jsp:forward page=""></jsp:forward>
5) response.sendRedirect("")
--%>
<%
pageContext.setAttribute("one", 100); //02_scopeTest.jsp 현재 페이지에서만 유효
request.setAttribute("two", 200);
session.setAttribute("three", 300);
application.setAttribute("uid", "ITWILL");
%>
<!-- 1) request.getAttribute("two) null값 -->
<!--
<a href="02_scopeResult.jsp">[SCOPE 결과 페이지 이동]</a>
-->
<!-- 2) request.getAttribute("two) null값 -->
<!--
<script>
alert("[SCOPE 결과 페이지 이동]");
location.href="02_scopeResult.jsp";
</script>
-->
<!-- 3) request.getAttribute("two) null값 -->
<!--
<form action="02_scopeResult.jsp">
<input type="submit" value="[SCOPE 결과 페이지 이동]">
</form>
-->
<!-- 4) 액션태그 페이지 이동 -->
<!-- request.getAttribute("two) 200 접근 가능
request 내부변수는 부모페이지(02_scopeTest.jsp)와 자식페이지(02_scopeResult.jsp)에서만 유효하다 -->
<%--
<jsp:forward page="02_scopeResult.jsp"></jsp:forward>
--%>
<%
//5) request.getAttribute("two) null값
//response.sendRedirect("02_scopeResult.jsp");
//6) request.getAttribute("two) 200 접근 가능
String view = "02_scopeResult.jsp";
RequestDispatcher rd = request.getRequestDispatcher(view);
rd.forward(request, response);
/*
내부변수 02_scopeTest.jsp(부모) 02_scopeResult.jsp(자식)
----------------------------------------------------------------
pageContext ○ X
request ○ ○ 또는 X
session ○ ○
application ○ ○
*/
%>
</body>
</html>
02_scopeResult.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_scopeResult.jsp</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>
정리해보면
내부변수 | 02_scopeTest.jsp(부모) | 02_scopeResult.jsp(자식) |
pageContext | O | X |
request | O | O 또는 X |
session | O | O |
application | O | O |
'웹개발 교육 > jsp' 카테고리의 다른 글
[55일] jsp (25) - web.xml (0) | 2022.10.17 |
---|---|
[55일] jsp (24) - session 내장 객체 (0) | 2022.10.17 |
[55일] jsp (22) - jsp 내부객체 (0) | 2022.10.17 |
[54일] jsp (21) - myweb 프로젝트(페이징) (0) | 2022.10.14 |
[53~54일] jsp (20) - myweb 프로젝트(게시판-검색) (0) | 2022.10.13 |