Sevlet Filter에서 Session 사용샘플

public class LoginFilter implements Filter{

	@Resource(name="userService")
	private UserService userService;

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

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("doFilter");

		HttpSession session = ((HttpServletRequest)request).getSession();

		User user = (User)session.getAttribute("auth");

		if(user==null){
			((HttpServletResponse)response).sendRedirect("");
		}

		User user2 = userService.get(user);

		//이거 꼭있어야 다음으로 넘어감
		chain.doFilter(request, response);

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("init");

	}

}

별것은 아니지만 그냥 기록

필요한 사람이 있을지도 모르니