通过struts.xml配置文件<package>标签里面的配置信息如下
<interceptors>
<!--定义权限验证拦截器-->
<interceptor name="myAuthorization"
class="cn.houserent.interceptor.AuthorizationInterceptor">
</interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="myAuthorization"></interceptor-ref>
</interceptor-stack>
</interceptors>
程序执行的时候会跑到下面这个类里来执行验证是否登录!
public class AuthorizationInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Map<String, Object> session=invocation.getInvocationContext().getSession();
User user=(User)session.get("user");
if(user==null){
return Action.LOGIN;
}else{
return invocation.invoke();
}
}
}