1) 개요
최상위 경로를 나타내는 ${contextPath}를 사용하기 위해 설정 필요
2) 클래스 작성
@WebFilter(filterName="initFilter", urlPatterns="/*")
public class InitFilter extends HttpFilter implements Filter {
private Logger logger = LoggerFactory.getLogger(InitFilter.class);
public void init(FilterConfig fConfig) throws ServletException {
logger.info("초기화 필터 생성");
}
public void destroy() {
logger.info("초기화 필터 파괴");
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
ServletContext application = request.getServletContext();
String contextPath = ( (HttpServletRequest)request ).getContextPath();
application.setAttribute("contextPath", contextPath);
chain.doFilter(request, response);
}
}