웹개발 교육/jsp

[55일] jsp (23) - SCOPE

2022. 10. 17. 14:44
● [페이지 이동]
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>

1) <a href="?"></a>
2) location.href=""
3) <form action=""></form>
4) <jsp:forward page=""></jsp:forward>

 

 

정리해보면

내부변수 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
'웹개발 교육/jsp' 카테고리의 다른 글
  • [55일] jsp (25) - web.xml
  • [55일] jsp (24) - session 내장 객체
  • [55일] jsp (22) - jsp 내부객체
  • [54일] jsp (21) - myweb 프로젝트(페이징)
ewok
ewok
기록장ewok 님의 블로그입니다.
ewok
기록장
ewok
전체
오늘
어제
  • 분류 전체보기
    • 웹개발 교육
      • HTML
      • CSS
      • JavaScript
      • Database
      • Java
      • jQuery
      • Ajax
      • Bootstrap
      • jsp
      • Spring
      • MyBatis
      • 프로젝트
    • JAVA
    • SpringBoot
      • 기초
      • AWS
      • 개인프로젝트
    • Spring Security
    • JPA
    • 테스트코드
    • Error
    • CS
      • 컴퓨터 구조
      • 이산수학
    • 알고리즘
      • 정리
      • Java
    • SQL
    • 자격증
      • SQLD
      • 정보처리기사
    • Git

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 브랜치
  • 버전 관리
  • 생성자
  • GIT
  • sqld 합격
  • branch
  • git bash
  • org.hibernate.tool.schema.spi.CommandAcceptanceException
  • org.springframework.beans.factory.UnsatisfiedDependencyException
  • 노랭이
  • SQLD
  • merge commit
  • this
  • base
  • sqld 자격증

최근 댓글

최근 글

hELLO · Designed By 정상우.
ewok
[55일] jsp (23) - SCOPE
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.