Filter is used in Java Web to prevent the browser from accessing internal URLs without logging in.
I won’t talk about the usage. I looked at the usage on the Internet and basically posted the code from Li Gang’s J2EE book.
It should be noted that if you directly set
So how to solve it? It is also said on the Internet to create a jspPage folder, put the jsp page in it, and then set
The recommended approach is: change the code in the Filter file
if( session.getAttribute("user")== null && !requestPath.endsWith(loginPage) && !requestPath.endsWith(LoginServlet ) && !requestPath.endsWith(".css")&&!requestPath.endsWith(".js") ){
request.setAttribute("loginError" , "You are not logged in yet");
request.getRequestDispatcher(loginPage).forward(request, response);
}