웹 프로그래밍 19-3(JSP)-내장객체(pageScope, requestScope, sessionScope, applicationScope)
*내장객체
내장객체는 따로 선언하지 않아도 존재하는 객체를 말한다.
전에 강의에서도 session도 선언하지 않고 session을 이용해 정보를 주고받은 것처럼 말이다.
위와같이 내장객체는 각자의 쓰임새가 있다.
pageScope
- page 영역은 한 번의 웹 브라우저(클라이언트)의 요청에 대해 하나의 JSP 페이지가 호출된다.
- 웹 브라우저의 요청이 들어오면 이때 단 한 개의 페이지만 대응이 된다.
- 따라서 page 영역은 객체를 하나의 페이지 내에서만 공유한다.
- page 영역은 pageContext 기본 객체를 사용한다.
requestScope
- request 영역은 한 번의 웹 브라우저(클라이언트)의 요청에 대해 같은 요청을 공유하는 페이지가 대응된다.
- 이것은 웹 브라우저의 한 번의 요청에 단지 한 개의 페이지만 요청될 수 있고, 때에 따라 같은 request 영역이면 두 개의 페이지가 같은 요청을 공유할 수 있다.
- 따라서 request 영역은 객체를 하나 또는 두 개의 페이지 내에서 공유할 수 있다.
- include 액션 태그, forward 액션 태그를 사용하면 request 기본 객체를 공유하게 되어서 같은 reqeust 영역이 된다.
- 주로 페이지 모듈화에 사용된다.
sessionScope
- session 영역은 하나의 웹 브라우저 당 1개의 session 객체가 생성된다.
- 즉, 같은 웹 브라우저 내에서는 요청되는 페이지들은 같은 객체를 공유하게된다.
applicationScope
- application 영역은 하나의 웹 어플리케이션 당 1개의 applicaition 객체가 생성된다.
- 즉, 같은 웹 어플리케이션에 요청되는 페이지들은 같은 객체를 공유한다.
※출저 : https://hyeonstorage.tistory.com/88
-실제로 예제를 통해 사용해보자
objel.jsp에서 정보를 저장하여
objelOk.jsp에서 값 출력을 해보자
===========================소스===================================
objel.jsp
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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body>
<form action="objelOk.jsp" method="POST"> 아이디 : <input type="text" name="id"><br /> 비밀번호 : <input type="password" name="pw"> <input type="submit" value="login"> </form>
<% application.setAttribute("application_name","application_value"); //application 객체 session.setAttribute("session_name", "session_value"); //session 객체 pageContext.setAttribute("page_name", "page_value"); //pageContext 객체 request.setAttribute("request_name","request_value"); //request 객체
%> </body> </html> |
objelOk.jsp
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 32 33 34 35 36 37 |
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> <% String id = request.getParameter("id"); String pw = request.getParameter("pw"); %>
아이디 : <%= id %> <br /> 비밀번호 : <%=pw %> <br /> <hr /> 아이디 : ${ param.id } <br /> 비밀번호 : ${ param.pw } <br /> 아이디 : ${ param["id"] } <br /> 비밀번호 : ${ param["pw"] } <br />
<hr />
applicationScope : ${ applicationScope.application_name }<br /> //값 출력 sessionScope : ${ sessionScope.session_name }<br /> //값 출력 pageScope : ${ pageScope.page_name }<br /> //값 출력 requestScope : ${ requestScope.request_name } //값 출력
<hr />
context 초기화 파라미터<br /> ${ initParam.con_name } <br /> ${ initParam.con_id } <br /> ${ initParam.con_pw } <br /> </body> </html> |
-출력 화면
objel.jsp
objelOk
'프로그래밍 정리 > JSP, Servlet, DB(oracle)' 카테고리의 다른 글
웹 프로그래밍 20-2(JSP)-JSTL 기초, Core를 사용해보자 (0) | 2020.01.06 |
---|---|
웹 프로그래밍 20-1(JSP)-JSTL 시작 (0) | 2020.01.06 |
웹 프로그래밍 19-2(JSP)-EL과 빈(bean) (0) | 2020.01.06 |
웹 프로그래밍 19-1(JSP)-EL(Expression Language) (0) | 2020.01.06 |
웹 프로그래밍 18(JSP,DB)-파일 업로드 (0) | 2020.01.06 |