[英]Java Servlet Filter redirect problem
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.
当过滤器重定向到登录页面时,登录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: AuthFilter筛选:
if (authorized == null && path.indexOf("Auth") == -1 && path.indexOf("Login") == -1 ) {
httpResponse.sendRedirect("Login");
return;
} else {
chain.doFilter(request, response);
}
Login servlet: 登录servlet:
// Just using a servlet in case I want more data sent to the jsp
Dispatcher.dispatch("views/login.jsp", request, response);
login.jsp: login.jsp的:
<img src="images/logo.png" />
The jsp is otherwise "normal", all required HTML tags are present. jsp在其他方面是“正常的”,所有必需的HTML标记都存在。 The "images" folder is in the default "web" folder of the project, alongside all the other jsp's and javascripts.
“images”文件夹位于项目的默认“web”文件夹中,与所有其他jsp和javascripts一起。
Thanks in advance for any help. 在此先感谢您的帮助。 :)
:)
- Stian - Stian
It's because of the relative paths. 这是因为相对路径。
Login
is in the root of the context Login
位于上下文的根目录中 /views/images/
/views/images/
So when you forward, the images are sought at /images
(because they are relative to the current address) instead of /views/images/
所以当你前进时,图像是在
/images
(因为它们是相对于当前地址)而不是/views/images/
How to resolve it. 如何解决它。 Two options:
两种选择:
Update: Make sure the images are NOT affected by the filter. 更新:确保图像不受过滤器影响。 two options:
两种选择:
request.getRequestURI()
request.getRequestURI()
检查这个 Could it be that your filter is also applied to image requests and redirects the request for logo.png
to login.jsp
? 可能是您的过滤器也应用于图像请求并将
logo.png
的请求重定向到login.jsp
?
If so, you could adjust the filter-mapping
in web.xml
. 如果是这样,您可以在
web.xml
调整filter-mapping
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.