Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 이클립스
- Graphic
- struts2
- 메소드
- 전화걸기
- OGNL
- layout
- 국제화
- 메서드
- 에러페이지
- oracle
- Spring
- Java
- paint
- 배열
- 기본
- 어노테이션
- JSP
- 안드로이드
- 클래스
- Menu
- Android
- mybatis
- 예외처리
- 생성자
- AWT
- Eclips
- 오버로딩
- JavaScript
- HTML
Archives
- Today
- Total
note
JSP 기본 객체와 영역 본문
Page,Request,Session
a.jsp 실행화면
a.jsp -> b.jsp 로 변경후 이동
b.jsp 실행화면
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
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은 다 공유할 수 있는 정보를 저장시키는데 사용함
자신이 저장한 데이터를 다른 클라이언트가 가져갈 수 있음
'JSP > 기본' 카테고리의 다른 글
| JSP include (0) | 2012.02.07 |
|---|---|
| <jsp:include> 액션 태그를 사용하여 페이지 모듈화 (0) | 2012.02.06 |
| JSP 기본 객체 사용하여 자원 읽기 (0) | 2012.02.06 |
| Servlet Context (0) | 2012.02.06 |
| JSP 서버정보 출력, 로그 메세지 기록 (0) | 2012.02.06 |