6
오브젝트가 HTTP의 세션 오브젝트에 바인드되거나 언 바운드 될 때 어떻게 통지받을 수 있습니까?HTTP 세션에 바인드/언 바운드 할 때 알림 받기
오브젝트가 HTTP의 세션 오브젝트에 바인드되거나 언 바운드 될 때 어떻게 통지받을 수 있습니까?HTTP 세션에 바인드/언 바운드 할 때 알림 받기
개체의 클래스를 HttpSessionBindingListener
으로 구현합시다. 당신이 개체의 클래스 코드 여부를 제어 할 수 없습니다 따라서 당신이 그 코드를 변경할 수없는 경우
public class YourObject implements HttpSessionBindingListener {
@Override
public void valueBound(HttpSessionBindingEvent event) {
// The current instance has been bound to the HttpSession.
}
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
// The current instance has been unbound from the HttpSession.
}
}
는 다음 대안은 HttpSessionAttributeListener
을 구현하는 것입니다.
@WebListener
public class YourObjectSessionAttributeListener implements HttpSessionAttributeListener {
@Override
public void attributeAdded(HttpSessionBindingEvent event) {
if (event.getValue() instanceof YourObject) {
// An instance of YourObject has been bound to the session.
}
}
@Override
public void attributeRemoved(HttpSessionBindingEvent event) {
if (event.getValue() instanceof YourObject) {
// An instance of YourObject has been unbound from the session.
}
}
@Override
public void attributeReplaced(HttpSessionBindingEvent event) {
if (event.getValue() instanceof YourObject) {
// An instance of YourObject has been replaced in the session.
}
}
}
참고 : 서블릿 2.5 또는 그 이상에 아직있을 때, web.xml
에서 <listener>
구성 항목에 의해 @WebListener
를 교체합니다.
도움을 주셔서 감사합니다. 이것은 내가 찾고있는 것입니다. :) – ramoh