Attribute(속성)
-Attribute(속성)이란?
Web Application 구성 컴포넌트들(Servlet,m JSP, Listener)이 공유하는 객체
-scope(적용영역)
- Attribute들을 공유하기 위한 공유 장소의 영역(저장장소)
- 공유 범위에 따라 3가지 영역이 있다.
1. requset scope : HttpServletRequest 이용
-요청 ~ 응답까지 공유
2. session scope : HttpSession 이용
-한명의 클라이언트(웹브라우저)가 로그인 ~ 로그아웃
3. application scope : ServletContext 이용
-Application 시작 ~ 종료시까지 공유
- 관련 메소드
Attribute는 key-value쌍으로 관리된다.
*setAttribute(String key, Object value) : 공유영역에 Attribute 저장 [Binding]
*getAttribute(String key) : Object value : 저장된 Attribute 조회 [lookup]
*removeAttribute(String key) : 저장된 Attribute 삭제
*getAttributeNames() : Enumeration : Attribute들에 연결된 name들 조회
<예제>
[SetAttributeServlet.java]
[GettAttributeServlet.java]
결과