Filter 상속 javax.servlet.Filter
구미에 맞게 3가지 메소드 오버라이딩
init
destroy
doFilter
@Slf4j
public class MyFirstFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
log.info("그냥 실행!");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
log.info("시작");
request.setAttribute("merong", "응");
chain.doFilter(request, response);
log.info("종료");
}
@Override
public void destroy() {
log.info("사라질 때 사용");
}
}
web.xml에 등록
<filter>
<filter-name>myFirstFilter</filter-name>
<filter-class>kr.pe.e7e.filter.MyFirstFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myFirstFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
위처럼 하기 싫음 @WebFilter(value = "/*",filterName = "myFirstFilter") 사용
작은 재미 오픈API (7) | 2022.05.10 |
---|---|
Security 맛보기 (0) | 2022.05.06 |
스케줄러(Scheduler,Quartz포함) (0) | 2022.05.04 |
인터셉터(가로채깅) (1) | 2022.05.03 |
Exception(예외) 처리 할꼉? (6) | 2022.05.02 |