Home >Web Front-end >HTML Tutorial >Filter does not filter CSS and JS_html/css_WEB-ITnose

Filter does not filter CSS and JS_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:49:201641browse

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 /*, your CSS and JS files will also be filtered out.

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 jspPage/*. I would like to say that this method may be suitable for simple page jumps, but I encountered Adjusting a website with a navigation bar will cause confusion and is not advisable.

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);

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn