⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logininterceptor.java

📁 Webwork+Spring+Freemake框架
💻 JAVA
字号:
package neo.core.common;

import neo.core.Constants;
import neo.core.util.QueryUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;

/**
 * 登录拦截器,用于阻止未登录用户访问系统
 */
public class LoginInterceptor implements Interceptor {
	protected final Log log = LogFactory.getLog(getClass());

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		Action action = (Action) invocation.getAction();
		String actionName = invocation.getInvocationContext().getName();
		if (action instanceof Anonymous || "login".equals(actionName)
				|| "logout".equals(actionName)) {
			return invocation.invoke();
		} else {
			if (ActionContext.getContext().getSession().get(
					Constants.LOGIN_USER) != null) {
				return invocation.invoke();
			}
		}

		ActionContext.getContext().getSession().put(Constants.ORIGINAL_URL,
				QueryUtil.getRequestURL(ServletActionContext.getRequest()));
		return Action.LOGIN;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -