JSF 2.0:如何获取在浏览器的地址栏中输入的URL [英] JSF 2.0: How to get the URL that is entered in the browser's address bar
问题描述
我的JSF应用程序将所有未登录的用户重定向到登录页面.当用户登录时,我希望应用程序重定向到用户最初在浏览器的地址栏中输入的页面.但是我不知道如何访问用户最初输入的URL,因为他会自动重定向到我在web.xml中配置的登录页面.
My JSF application redirects any user who is not logged in to the login page. When the user logs in, I want the application to redirect to the page the user has initially entered in the browser's adress bar. But I don't know how to access the url the user has initially entered, since he is automatically redirected to the login page which I configured in the web.xml.
推荐答案
容器托管的安全性对此没有任何API提供的功能.最好的选择是用Filter
类替换<login-config>
,该类大致如下:
The container managed security doesn't have any API-provided facilities for this. Your best bet is to replace the <login-config>
by a Filter
class which does roughly like this:
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);
}
然后在您的登录名中:
request.login(username, password);
externalContext.redirect((String) request.getSession().getAttribute("from"));
这篇关于JSF 2.0:如何获取在浏览器的地址栏中输入的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!