我的应用程序是使用 Struts2 开发的,我有一个拦截器,可以根据会话属性验证用户是否登录。现在让我们说会话超时并且用户尝试再次登录。登录成功后,我如何处理重新登录用户并将用户引导回他们正在处理的最后一页......比如说 page3.jsp?
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>