日期:2014-05-16 浏览次数:20434 次
@WebFilter(filterName = "/LoginFilter") public class LoginFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest)request; HttpServletResponse httpResponse = (HttpServletResponse)response; String servletPath = httpRequest.getServletPath(); if (servletPath.equals("/login.jsp")) { chain.doFilter(httpRequest, httpResponse); return; } HttpSession session = httpRequest.getSession(); if (session.getAttribute("username") == null) { httpResponse.sendRedirect(httpRequest.getContextPath() + "/login.jsp"); } else chain.doFilter(request, response); } public void init(FilterConfig fConfig) throws ServletException { } }
@WebFilter(filterName = "/LoginFilter")
@WebFilter(filterName = "/LoginFilter", urlPatterns = {"/*"})