public class PrivilegeInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept (ActionInvocation actionInvocation) throws Exception {
User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user" );
if (user == null ){
ActionSupport actionSupport = (ActionSupport) actionInvocation.getAction();
actionSupport.addActionError("没有登录, 没有权限访问!!!" );
return actionSupport.LOGIN;
}else {
return actionInvocation.invoke();
}
}
}
<interceptors >
<interceptor name ="privilegeInterceptor" class ="com.lyric.ssh.web.interceptor.PrivilegeInterceptor" > </interceptor >
</interceptors >
<interceptor-ref name ="privilegeInterceptor" >
<param name ="excludeMethods" > regist,login</param >
</interceptor-ref >
<interceptor-ref name ="defaultStack" />