본문 바로가기

Programming/SCWCD

문제5 풀이

5. Given the definition of MyObject and that an instance of MyObject is bound as a session attribute:


8   package com.example;

9   public class MyObject implements

10  javax.servlet.http.HttpSessionBindingListener {

11  // class body code here

12  }

Which is true?

A. Only a single instance of MyObject may exist within a session.

B. The unbound method of the MyObject instance is called when the session to which it is bound times out.

C. The com.example.MyObject must be declared as a servlet event listener in the web application deployment descriptor.

D. The valueUnbound method of the MyObject instance is called when the session to which it is bound times out.


위의 문제는 HttpSessionBindingListener에 대해 알고 있으면 풀 수 있는 문제입니다.

이 리스너는 속성이 세션에 추가될 때 속성의 정보를 데이터베이스에서 읽어 온다든지, 아니면 세션에서 제거될 때 속성의 정보로 데이터베이스를 업데이트한다든지 할 때 사용합니다.

간단히 말하자면, HttpSessionBindingListener를 구현한 클래스의 객체가 있을 텐데(코딩을 보면 9~10번째 줄),  위의 예제와 같은 경우 MyObject 객체가 세션에 추가되거나 제거되면 알려준다는 말입니다. 이 추가와 제거되는 상황에서 실행되도록 하는 메소드가 있는데, 그것은 각각 valueBoundvalueUnbound입니다.




이 글은 스프링노트에서 작성되었습니다.