struts2用户登录和拦截器的问题
我在struts。xml里加入了拦截器,如下:
<interceptors>
<interceptor name="auth" class="com.aa.common.interceptor.AuthorizationInterceptor" />
<interceptor-stack name="authStack">
<interceptor-ref name="auth" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="authStack" />
<global-results>
<result name="login" type="redirect">/index.jsp</result>
</global-results>
我的类AuthorizationInterceptor如下:
public class AuthorizationInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = -1689526894183598040L;
@Override
public String intercept(ActionInvocation ai) throws Exception {
Map session = ai.getInvocationContext().getSession();
SessionInfo sessionInfo = (SessionInfo) session.get("LoginInfoKey");
if (sessionInfo != null) {
return ai.invoke();
} else {
return Action.LOGIN;
}
}
}
我的目的就是如果用户没有登录,但他想访问系统里的页面,让他跳转到登录页,如果登录了,就继续执行。但是按这样配置了,连登录了也给拦截了(因为登录时,在session里肯定没有数据)。请大家给一个解决方案,谢谢。最好说的细点。