JSP2010. 4. 9. 10:31

# Filter
- Request를 필터링하는 역할(보안, 인증, 인코딩, XSL/T, 로깅 ... )
- javax.servlet.Filter인터페이스를 구현한 클래스를 필터클래스로 사용
- Filter인터페이스의 메소드
 1) void init(FilterConfig filterConfig)
  Filter의 설정정보를 가진 FilterConfig를 인자로 받아서 Fillter초기화시 한번만 호출
 2)void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  Filter의 작업을 정의,FilterChain을 통해 적용될 Filter들의 정보를 가져옴
 3)void destroy()
  Filter가 메모리에서 해제되기 전에 ㅣFilter가 사용한 자원을 해제 
 
# Listener
- 어플리케이션에서 일어나는 여러가지 이벤트를 자동 감지해서
  이벤트에 따른 처리를 가능하도록 함
- 리스너의 종류
 1) javax.servlet.ServletContextListener
  - void contextDestroyed(ServletContextEvent sce)
           컨텍스트가 메모리에서 제거될때(웹어플 종료 직전 호출)
   - void contextInitialized(ServletContextEvent sce)
           컨텍스트가 메모리에 로딩될때 (웹어플 시작시)
 2) javax.servlet.ServletContextAttributeListner
  - void attributeAdded(ServletContextAttributeEvent scab)
         컨텍스트 유효범위에 속성변수가 추가될때(application.setAttribute("a", new Date())) 
   - void attributeRemoved(ServletContextAttributeEvent scab)
    컨텍스트 유효범위에 속성변수가 제거될때(application.removetAttribute("a", new Date()))
   - void attributeReplaced(ServletContextAttributeEvent scab)
    컨텍스트 유효범위에 속성변수가 대체될때
    application.setAttribute("a", new Object())
    application.setAttribute("a", new Date())
 3) javax.servlet.http.HttpSessionListner
  - void sessionCreated(HttpSessionEvent se)
   세션이 생성될때         
   - void sessionDestroyed(HttpSessionEvent se)
            세션이 종료될때
 4) javax.servlet.http.HttpSessionAttributeListener
  - void attributeAdded(HttpSessionBindingEvent se)
          세션 유효범위에 속성변수가 추가될때
          session.setAttribute("userid", "홍길동);
   - void attributeRemoved(HttpSessionBindingEvent se)
         세션 유효범위에 속성변수가 제거될때
          session.removeAttribute("userid");
   - void attributeReplaced(HttpSessionBindingEvent se)
            세션 유효범위에 속성변수가 대체될때
          session.setAttribute("홍길동");
          session.setAttribute("강감찬");
 5) javax.servlet.http.HttpSessionActivationLIstener 
  세션이 활성화 될때
  -void sessionDidActivate(HttpSessionEvent se)
   세션이 활성화된 후          
   -void sessionWillPassivate(HttpSessionEvent se)
             세션이 비활성화되기 전
 6) javax.servlet.http.HttpSessionBindingLIstener
  세션이 클라이언트에 바인딩 될때 
  - void valueBound(HttpSessionBindingEvent event)
          세션이 클라이언트에 바인딩될 때
   - void valueUnbound(HttpSessionBindingEvent event)
          세션이 클라이언트에 바인딩 해제 될 때
        
  
 
 
 
 
 
 
 
 
 
 
 
Posted by Tiwaz