struts2拦截器示例

public class AuthorityInterceptor implements Interceptor {
public static final String SEESION_KEY = "com_adsfreeway_dss_session";
public static final String SESSION_LOGIN_USERNAME_KEY = "SESSION_LOGIN_USERNAME";
public static final String SESSION_LOGIN_PASSWORD_KEY = "SESSION_LOGIN_PASSWORD";
public static final String GOTO_URL_KEY = "GOTO_URL";

private static final Logger log4j = Logger.getLogger(AuthorityInterceptor.class);

public void destroy() {

}

public void init() {

}

public String intercept(ActionInvocation invocation) throws Exception {
SuperAction action = (SuperAction) invocation.getAction();

Map session = ActionContext.getContext().getSession();
LoginUser loginUser = (LoginUser) session.get(SEESION_KEY);
if (loginUser != null) {
action.setLoginUser(loginUser);
} else {
HttpServletRequest request = ServletActionContext.getRequest();
StringBuffer url = request.getRequestURL();
if (request.getQueryString() != null) {
url.append(request.getQueryString());
}
session.put(GOTO_URL_KEY, url.toString());
return "login_action";
}

return invocation.invoke();
}
}

你可能感兴趣的:(log4j)