1.编写拦截器

public class PrivilegeInterceptor extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		//判断session中是否有用户登录信息
		User exitUser = (User)ServletActionContext.getRequest().getSession().getAttribute("exitUser");
		if(exitUser == null){
			//存储错误信息,跳转到登录页面
			ActionSupport actionSupport = (ActionSupport)invocation.getAction();
			actionSupport.addActionError("您还没有登录!没有权限访问");
			return actionSupport.LOGIN;
		}else{
			return invocation.invoke();
		}
	}
	
}

2.配置拦截器

<!-- 定义拦截器 -->
<interceptors>
	<interceptor name="PrivilegeInterceptor" class="crm.web.interceptor.PrivilegeInterceptor"></interceptor>
</interceptors>

SSH开发配置权限拦截器

SSH开发配置权限拦截器

 

 

 

相关文章: