Filter does not filter CSS and JS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:49:20
Original
1626 people have browsed it

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

}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!