Reputation: 886
I'm having a problem with my authentication filter. When the filter redirects to the login page, no images gets displayed in the login JSP. However, if I go to the login page manually after I'm logged in, the images are displayed.
I don't understand why this is happening! I appreciate any help. :-)
AuthFilter:
if (authorized == null && path.indexOf("Auth") == -1 && path.indexOf("Login") == -1 ) {
httpResponse.sendRedirect("Login");
return;
} else {
chain.doFilter(request, response);
}
Login servlet:
// Just using a servlet in case I want more data sent to the jsp
Dispatcher.dispatch("views/login.jsp", request, response);
login.jsp:
<img src="images/logo.png" />
The jsp is otherwise "normal", all required HTML tags are present. The "images" folder is in the default "web" folder of the project, alongside all the other jsp's and javascripts.
Thanks in advance for any help. :)
- Stian
Upvotes: 6
Views: 19198
Reputation: 597026
It's because of the relative paths.
Login
is in the root of the context/views/images/
So when you forward, the images are sought at /images
(because they are relative to the current address) instead of /views/images/
How to resolve it. Two options:
Update: Make sure the images are NOT affected by the filter. two options:
request.getRequestURI()
Upvotes: 8
Reputation: 262474
Could it be that your filter is also applied to image requests and redirects the request for logo.png
to login.jsp
?
If so, you could adjust the filter-mapping
in web.xml
.
Upvotes: 2