我已经为我想要保护的任何页面配置了一个身份验证过滤器。但是,当它尝试重定向到登录页面时,我遇到以下错误
com.sun.faces.context.FacesFileNotFoundException
..这是我的过滤器
@WebFilter(filterName = "Authentication Filter", urlPatterns = { "/pages/*" }, dispatcherTypes = {
DispatcherType.REQUEST, DispatcherType.FORWARD })
public class AuthenticationFilter implements Filter {
static final Logger logger = Logger.getLogger(AuthenticationFilter.class);
private String contextPath;
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (httpRequest.getUserPrincipal() == null) {
httpResponse.sendRedirect(contextPath
+ "/faces/pages/public/login.xhtml");
return;
}
chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
contextPath = fConfig.getServletContext().getContextPath();
}
}
..我的 web.xml 被映射到 faces servlet 的这个代码
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
不确定,但我已验证该路径存在于我的项目文件夹中
+pages
+public
-login.xhtml
生成的路径是
http://localhost:8080/MyApp/faces/pages/public/login.xhtml
有人知道原因吗?