//拦截器代码步骤
/*
* 1.写个登录拦截器
* 2.在struts.xml配置一个登录拦截器
* 3.配置一个拦截器分组,把登录拦截器和struts默认拦截器添加进组
* 4.修改struts默认拦截器
* 5.在登录拦截器排除一些不需要拦截的方法excludeMethods
* */
1、登录拦截器代码
package com.wzt.bos.web.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.wzt.bos.model.User;
import org.apache.struts2.ServletActionContext;
public class BOSLoginInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
//是否登录局
User user =(User) ServletActionContext.getRequest().getSession().getAttribute("loginUser");
//用户不为空就放行
if(user!=null){
return actionInvocation.invoke();
}
return "login";//回到登录页面
}
}
</