1. web.xml 필터 설정
<filter>
<filter-name>MainFilter</filter-name>
<filter-class>secretary.common.filter.MainFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MainFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2. Filter Class 생성
package secretary.common.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
public class MainFilter implements Filter {
/**
* 1. 세션에 사용자 정보가 있는지 체크
* 2. 세션에 사용자 정보가 없으면 id/pw 화면으로
*/
// DEBUG, INFO, WARN, ERROR, FATAL
public Logger logger = Logger.getLogger(this.getClass());
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// UTF-8로 Response 인코딩
response.setCharacterEncoding("UTF-8");
String requestUri = ((HttpServletRequest)request).getRequestURI();
String contextPath = ((HttpServletRequest)request).getContextPath();
logger.info("contextPath : "+contextPath);
logger.info("requestUri : "+requestUri);
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig config) throws ServletException {
//logger.info("===== init filter =====");
}
@Override
public void destroy() {
//logger.info("===== destroy filter =====");
}
}
'개발 > 개발환경설정' 카테고리의 다른 글
util:properties 설정 (0) | 2020.08.10 |
---|---|
Tiles 설정 (0) | 2020.08.10 |
Interceptor 설정 (0) | 2020.03.17 |
Aspectj + 어노테이션으로 로그남기기 (0) | 2020.03.17 |
LOG4J 설정 (0) | 2020.03.17 |