Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JBoss Seam在使用登录页面后是否可以重定向用户的“上次访问页面”?_Java_Jsf_Seam - Fatal编程技术网

Java JBoss Seam在使用登录页面后是否可以重定向用户的“上次访问页面”?

Java JBoss Seam在使用登录页面后是否可以重定向用户的“上次访问页面”?,java,jsf,seam,Java,Jsf,Seam,注 我有ServletFilter,它用于检查用户是否已通过使用登录。如果用户未登录,则重定向到login.xhtml 我的问题 用户登录后,我的程序总是根据导航规则重定向dashboard.xml。我想自动重定向上次访问的页面。你能提供可能的方法吗 目前我的解决方案就是为这个而工作 但是,我不乐意使用它。接缝支撑吗?你能提供更好的方法吗 在我的ServletFilter中,我保留最后访问的页面如下 AuthenticationFilter.java httpSession.setAttribu

我有ServletFilter,它用于检查用户是否已通过使用登录。如果用户未登录,则重定向到login.xhtml

我的问题

用户登录后,我的程序总是根据导航规则重定向dashboard.xml。我想自动重定向上次访问的页面。你能提供可能的方法吗

目前我的解决方案就是为这个而工作

但是,我不乐意使用它。接缝支撑吗?你能提供更好的方法吗

在我的ServletFilter中,我保留最后访问的页面如下

AuthenticationFilter.java

httpSession.setAttribute(Constants.ORIGINAL_VIEW_KEY, requestPath);
在my LoginBean中,在用户登录后重定向上次访问的页面

LoginBean.java

ELContext elContext = facesContext.getELContext();
Application application = facesContext.getApplication();
ExpressionFactory eFactory = application.getExpressionFactory();
ValueExpression binding = eFactory.createValueExpression(elContext, "#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY + "}", Visit.class);
binding.setValue(elContext, visit);

ValueExpression originalViewBinding = eFactory.createValueExpression(elContext, "#{" + Constants.ORIGINAL_VIEW_SCOPE + Constants.ORIGINAL_VIEW_KEY + "}", String.class);

String originalViewId = (String) originalViewBinding.getValue(elContext); <--- last visited view id.

UIViewRoot viewRoot = application.getViewHandler().createView(facesContext, originalViewId) ;
facesContext.setViewRoot(viewRoot);
facesContext.renderResponse();

从login.page.xml中删除以下内容

<navigation from-action="#{identity.login}">
  <rule if="#{identity.loggedIn}">
     <redirect view-id="/view/dashboard.xhtml"/>
  </rule>
如果使用了标识和凭据,则页面重定向到上次访问的页面要访问该页面,需要在登录后使用自动登录。我们需要在component.xml中进行如下配置

component.xml

<?xml version="1.0" encoding="UTF-8"?>
<components ----->
   <event type="org.jboss.seam.security.loginSuccessful">
      <action execute="#{redirect.returnToCapturedView}"/>
   </event>
</components>   

我的问题是上次访问页面您希望用户返回到他上次访问该站点时的页面吗?Seam默认情况下不提供该功能,您应该添加一个全局页面操作,该操作存储在DB上,例如当前页面的视图id,然后在登录时,将它们重定向到该视图,检查重定向组件的源代码以了解如何重定向的线索