我的JSF应用程序重定向未登录到登录页面的任何用户.当用户登录时,我希望应用程序重定向到用户最初在浏览器的地址栏中输入的页面.但我不知道如何访问用户最初输入的URL,因为他被自动重定向到我在web.xml中配置的登录页面.
容器管理的安全性没有任何API提供的设施.你最好的选择是替换<login-config>一个Filter类似于这样的类:
HttpServletRequest httpreq = (HttpServletRequest) request;
HttpServletResponse httpres = (HttpServletResponse) response;
if (httpreq.getUserPrincipal() == null) {
httpreq.getSession().setAttribute("from", httpreq.getRequestURI());
httpres.sendRedirect("login.jsf");
} else {
chain.doFilter(request, response);
}
Run Code Online (Sandbox Code Playgroud)
然后在你的登录信息中:
request.login(username, password);
externalContext.redirect((String) request.getSession().getAttribute("from"));
Run Code Online (Sandbox Code Playgroud)