Jsf 如何获取最初请求的页面的url?
我使用以下web.xml设置将未登录的用户定向到/faces/loginPage.xhtml。Jsf 如何获取最初请求的页面的url?,jsf,jsf-2,Jsf,Jsf 2,我使用以下web.xml设置将未登录的用户定向到/faces/loginPage.xhtml。 在/faces/loginPage.xhtml中,我将对用户进行身份验证,并将用户重定向到主页 现在,我想将用户重定向到她最初请求的页面,而不是主页。我该怎么做?具体来说,如何获取最初请求的页面的url <security-constraint> <display-name>MyConstraint</display-name> <web-re
在/faces/loginPage.xhtml中,我将对用户进行身份验证,并将用户重定向到主页 现在,我想将用户重定向到她最初请求的页面,而不是主页。我该怎么做?具体来说,如何获取最初请求的页面的url
<security-constraint>
<display-name>MyConstraint</display-name>
<web-resource-collection>
<web-resource-name>wrcoll</web-resource-name>
<description />
<url-pattern>/faces/secured/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description />
<role-name>myUser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>my_ldap_domain</realm-name>
<form-login-config>
<form-login-page>/faces/loginPage.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
霉菌
沃科尔
/面/安全/*
我的用户
形式
my_ldap_域
/faces/loginPage.xhtml
/error.xhtml
您似乎是通过JSF管理的bean而不是通过j_security_check
执行登录。因为如果您使用的是后者,这已经被自动考虑在内了
基于表单的身份验证登录页面通过通常的Servlet API方式显示。因此,最初请求的页面的请求URI作为请求属性可用,其名称由指定,其值为
因此,在EL上下文中,它可以作为
String originalURL = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("javax.servlet.forward.request_uri");
#{requestScope['javax.servlet.forward.request_uri']}
在JSF上下文中,它可以作为
String originalURL = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("javax.servlet.forward.request_uri");
这需要在初始请求中收集,而不是在提交表单中收集。最简单的方法是在附加到页面的@ViewScoped
托管bean的构造函数中获取它。使用@RequestScoped
bean的另一种选择是在登录表单中用该值将一个普通HTML
括起来,并将其设置为@ManagedProperty
详细答案如下