struts2 标签 怎样把变量值作为变量输出

2024-11-08 00:05:15
推荐回答(1个)
回答1:

首先,struts2进行权限验证是用拦截器做的
一个简单的登录拦截器示例如下:
package com.zdf.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.zdf.entity.Admin;

@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor{

@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
Admin admin = (Admin)invocation.getInvocationContext().getSession().get("ADMIN");
if(admin!=null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}

}