@WebFilter ( "/ *" ) public class LoginFilter the implements the Filter { public void the doFilter (the ServletRequest REQ, the ServletResponse RESP, the FilterChain catena alberghiera) throws ServletException, IOException { // cast the HttpServletRequest Request = (the HttpServletRequest) REQ; // Get the resource request path uri = String request.getRequestURI (); // determine whether the resource contains relevant landing iF (uri.contains ( "/ the login.jsp") || uri.contains ( "/ the LoginServlet") || uri.contains ( "/ css / ") || uri.contains (" / js / ") || uri.contains (" / checkCodeServlet ")) { // contains the user just want to log in, release the chain.doFilter (REQ, RESP); } the else { // does not contain, need to verify the user login login // 3. acquired from the session User Object Request.getSession = User () the getAttribute ( "User." ); IF ( ! the User = null ) { // landed, release chain.doFilter (REQ, RESP); } the else { // not logged in, jump page request.setAttribute ( "login_msg", "You are not logged in, please login" ); request.getRequestDispatcher ( "/login.jsp" ) .forward (Request, RESP); } } } public void init(FilterConfig config) throws ServletException { } public void destroy() { } }