/**
@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>
//为什么我进登录页面也会拦截
http://blog.csdn.net/axin66ok/article/details/7321430
少了一个配置中的属性,在action中配置一个属性name=execludeMethods. 里面写login。表示放行login方法