Page,Request,Session




a.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP 4개 영역 및 기본객체 사용</title>
</head>
<body>
<%
	pageContext.setAttribute("season","봄");
	String season = (String)pageContext.getAttribute("season");
	
	request.setAttribute("season1", "여름");
	String season1 = (String)request.getAttribute("season1");
	
	session.setAttribute("season2", "가을");
	String season2 = (String)session.getAttribute("season2");
%>
page영역 : <%=season %><br/>
Request영역 : <%=season1 %><br/>
session영역 : <%=season2 %>
</body>
</html>


b.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP 4개 영역 및 기본객체 사용</title>
</head>
<body>
<%
String season = (String)pageContext.getAttribute("season");
String season1 = (String)request.getAttribute("season1");
String season2 = (String)session.getAttribute("season2");
%>
page영역 : <%=season %><br/>
request영역 : <%=season1 %><br/>
session영역 : <%=season2 %>
</body>
</html>






Application




setApplicationAttribute.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
    	String name = "id";
    	String value = "dragon";
    	
    	application.setAttribute(name, value);
    %>
<!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=UTF-8">
<title>application 속성 지정</title>
</head>
<body>
application 기본 객체의 속성 설정 :
<%=name %> = <%= value %>
</body>
</html>


viewApplicationAttribute.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.util.Enumeration" %>
<!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=UTF-8">
<title>application 기본 객체 속성 보기</title>
</head>
<body>
<%
	Enumeration attrEnum = application.getAttributeNames();
while(attrEnum.hasMoreElements()){
	String name = (String)attrEnum.nextElement();
	Object value = application.getAttribute(name);
%>
application 속성 : <b><%=name %></b> = <%=value %><br/>
<%} %>
</body>
</html>





Application 사용시 주의사항

데이터 보관시 동기화 문제가 생김

Client를 구분하지 못하므로

Application은 다 공유할 수 있는 정보를 저장시키는데 사용함

자신이 저장한 데이터를 다른 클라이언트가 가져갈 수 있음 











+ Recent posts