2012-09-05 30 views
0

我的应用程序是使用Struts2开发的,我有一个拦截器,用于验证用户是否登录或不基于会话属性。现在让我们说会话超时,用户再次尝试登录。一旦登录成功,我该如何处理重新登录用户并将用户导回到他们工作的最后一页......说page3.jsp ??struts2会话超时重新登录到最后一次访问页面

loginInterceptor是

public class LoginInterceptor extends AbstractInterceptor { 
    @Override 
    public String intercept(final ActionInvocation invocation) throws Exception { 
    Map<String, Object> session = ActionContext.getContext().getSession(); 

    String userLoggedin = (String) session.get("userLoggedin "); 
    Object action = invocation.getAction(); 

    // user is not logged in yet 
    if(userLoggedin == null){  


     // public pages that dont require login 
     if (action instanceof LoginNotRequired) { 
       return invocation.invoke(); 

     } 

     // Pages that require the user to be logged in - user not logged in yet 
     if (!(action instanceof LoginAction)) { 
      return "loginRedirect"; 

     }  

    } 

    // user is logged in 
    if (userLoggedin.equals("true")) { 
     return invocation.invoke(); 

    } 

    return invocation.invoke(); 
} 

}

struts.xml中定义

<interceptors> 
     <interceptor name="login" class="com.mypackage.LoginInterceptor">     
      </interceptor> 
     <interceptor-stack name="myStack"> 
      <interceptor-ref name="login"></interceptor-ref> 
      <interceptor-ref name="defaultStack"></interceptor-ref> 
     </interceptor-stack> 
    </interceptors> 

    <default-interceptor-ref name="myStack"></default-interceptor-ref> 

    <global-results> 
     <result name="loginRedirect" type="redirect">/index.jsp</result> 
    </global-results> 

回答

0

你需要坚持跨会话去除的信息。这意味着应用程序范围中的user id/name =>last page映射,DB等,以及拦截器,该拦截器根据用户的上次请求保持此信息为最新。

您也可能将这些信息保存在客户端,例如在cookie中。

登录只会检查是否存在所述数据,如果找到则重定向到该数据。

这有很多潜在的问题。例如,如果用户的工作流程依赖于在他们的会话中具有特定信息,那么该信息现在已经消失,并且需要被恢复。

+0

你能告诉我这个拦截器是如何工作的吗?我如何获取当前用户页面信息?如何告诉从5小时后的应用范围删除此userid-> lastpage map? – rr87

相关问题