联系人管理-权限拦截器| CRM客户关系管理系统项目 实战八(Struts2+Spring+Hibernate)解析+源代码
一、实现权限的的拦截器
1、编写一个类去继承拦截器的类
在interceptor下创建PrivilegeInterceptor类
编写权限拦截器
package com.itzheng.crm.web.inertceptor;
import org.apache.struts2.ServletActionContext;
import com.itzheng.crm.domain.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
/*
* 权限拦截器
*/
public class PrivilegeInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
// 判断sesssion当中是否有登录的用户的信息
User existUser = (User) ServletActionContext.getRequest().getSession().getAttribute("existUser");
if (existUser == null) {
// 存错误信息,页面跳转到登录页面
ActionSupport actionSupport = (ActionSupport) invocation.getAction();
actionSupport.addActionError("您还没有登录!没有访问权限");
return actionSupport.LOGIN;
} else {
// 已经登录了
return invocation.invoke();
}
}
}
2、配置拦截器(配置拦截器并在不同的action当中引入对应的拦截器)
在struts.xml当中
将login.jsp配置为全局的