package com.sys.controller;


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 javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

public class LogFilter implements Filter{
	private static final Logger logger = Logger.getLogger(LogFilter.class);

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("----过滤器初始化----");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		// TODO Auto-generated method stub
		//对request和response进行一些预处理
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		String uri = httpRequest.getRequestURI();
		logger.info("uri========"+uri+";params========"+httpRequest.getParameterMap());
//		HttpSession httpSession = httpRequest.getSession();
//		if(!"/login.jsp".equals(uri) && !"/sys/login.do".equals(uri)) {
//			if (httpSession == null || httpSession.getAttribute("user") == null) {
//				httpResponse.sendRedirect(httpRequest.getContextPath() + "/login.jsp");
//			}
//		}
		chain.doFilter(request, response);  //让目标资源执行，放行


	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		System.out.println("----过滤器销毁----");
	}
	
	
}
