package wge.learn.shop.interceptor;
import org.apache.struts2.ServletActionContext;
import wge.learn.shop.adminuser.vo.AdminUser;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
/**
* 权限拦截器:
* @author
*
*/
public class PrivilegeInterceptor extends MethodFilterInterceptor{
@Override
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
// 判断是否登录,如果登录,放行,没有登录,跳转到登录页面.
AdminUser adminUser = (AdminUser) ServletActionContext.getRequest()
.getSession().getAttribute("existAdminUser");
if(adminUser != null){
// 已经登录过
return actionInvocation.invoke();
}else{
// 跳转到登录页面:
ActionSupport support = (ActionSupport) actionInvocation.getAction();
support.addActionError("您还没有登录!没有权限访问!");
return ActionSupport.LOGIN;
}
}
}
Struts拦截器判断用户是否登陆
最新推荐文章于 2024-06-15 16:58:23 发布