日期:2014-05-19 浏览次数:20676 次
import com.chenghui.entity.User; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; /** * 验证用户是否登录 * @author Administrator * */ public class CheckIsLoginInterceptor extends AbstractInterceptor{ private static final long serialVersionUID = 5572804837134361839L; @Override public String intercept(ActionInvocation actionInvocation) throws Exception { User user = (User)actionInvocation.getInvocationContext().getSession().get("user"); if(user==null){ ActionContext.getContext().getSession().put("loginMessage", "请先登录!"); return Action.LOGIN; } return actionInvocation.invoke(); } }