com.haoxuer.discover.web.base.BaseAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discover-website Show documentation
Show all versions of discover-website Show documentation
discover网站配置模块,主要管理网站主题,网站配置等功能
package com.haoxuer.discover.web.base;
import com.haoxuer.discover.web.data.common.InitConfig;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class BaseAction {
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
public HttpServletResponse getResponse() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
}
public HttpSession getSession() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
}
protected String getView(String view) {
String theme = InitConfig.getWebConfig().getAdminTheme();
if (StringUtils.isEmpty(theme)) {
theme = "default";
}
return "/tenant/" + theme + "/" + view;
}
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (StringUtils.hasText(ip) && !"unknown".equalsIgnoreCase(ip)) {
return ip;
} else {
ip = request.getHeader("X-Forwarded-For");
if (StringUtils.hasText(ip)&& !"unknown".equalsIgnoreCase(ip)) {
int index = ip.indexOf(44);
return index != -1 ? ip.substring(0, index) : ip;
} else {
return request.getRemoteAddr();
}
}
}
}