/**
- 判断用户是否登录的一个拦截器
-
@author Administrator
*
*/
public class LoginInterceptor extends MethodFilterInterceptor{protected String doIntercept(ActionInvocation invocation) throws Exception {
//获取session
User user = (User)ServletActionContext.getRequest().getSession().getAttribute("existUser");
if(user==null){
//说明用户没有登录
return Action.LOGIN;
}
return invocation.invoke();
}
}
//配置文件
<!-- 自定义拦截器 -->
login
<!-- 默认拦截器 -->
<default-interceptor-ref name="mylogin"></default-interceptor-ref>
<!-- 配置全局跳转页面 -->
<global-results>
<result name="login">/login/login.jsp</result>
</global-results>
</package>
//为什么我进登录页面也会拦截