![这样的](https://img-blog.csdn.net/20160226111027254)
javascript代码
function detectOS() {
var sUserAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if (isLinux) return "Linux";
if (isWin) {
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Windows 2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "Windows XP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Windows 2003";
var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "Windows Vista";
var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Windows 7";
}
return "other";
}
function userAgent(){
var ua = navigator.userAgent;
ua = ua.toLowerCase();
var match = /(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
!/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || [];
switch(match[1]){
case "msie":
return "Internet Explorer "+parseInt(match[2]);
break;
case "webkit":
return "safari or chrome"+parseInt(match[2]);
break;
case "opera":
return "opera"+parseInt(match[2]);
break;
case "mozilla":
return "mozilla Firefox"+parseInt(match[2]);
break;
default:
break;
}
}
function openWords(conId){
window.location.href="${pageContext.request.contextPath}/content/edit.htm?contentId="+conId;
}
后台获取ip代码
/**
* 获取访问者IP
* 在一般情况下使用Request.getRemoteAddr()即可,但是经过nginx等反向代理软件后,这个方法会失效。
* 本方法先从Header中获取X-Real-IP,如果不存在再从X-Forwarded-For获得第一个IP(用,分割),
* 如果还不存在则调用Request .getRemoteAddr()。
*
* @param request
* @return
*/
protected String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) {
return ip;
}
ip = request.getHeader("X-Forwarded-For");
if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) {
int index = ip.indexOf(',');
if (index != -1) {
return ip.substring(0, index);
} else {
return ip;
}
} else {
return request.getRemoteAddr();
}
}
内存获取
public class OsInfo {
public String getTotalMemory() {
DecimalFormat dcmFmt = new DecimalFormat("0.0");
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
totalvirtualMemory = osmxb.getTotalPhysicalMemorySize();
float totals = (float) totalvirtualMemory / (1024 * 1024);
return dcmFmt.format(totals);
}
public String getFreeMemory() {
DecimalFormat dcmFmt = new DecimalFormat("0.0");
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
float frees = (float) freePhysicalMemorySize / (1024 * 1024);
return dcmFmt.format(frees);
}
public String getUsedMemory() {
DecimalFormat dcmFmt = new DecimalFormat("0.0");
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
totalvirtualMemory = osmxb.getTotalPhysicalMemorySize();
float totals = (float) totalvirtualMemory / (1024 * 1024);
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
float frees = (float) freePhysicalMemorySize / (1024 * 1024);
float compare = (float) (totals - frees);
return dcmFmt.format(compare);
}
}
HashMap<String, String> osInfo = new HashMap<String, String>()
osInfo.put("osName", (String) System.getProperty("os.name"))
osInfo.put("osArch", System.getProperty("os.arch"))
osInfo.put("osVersion", System.getProperty("os.version"))
osInfo.put("jvmName", System.getProperty("java.vm.name"))
osInfo.put("jvmVersion", System.getProperty("java.vm.version"))
osInfo.put("javaVersion", System.getProperty("java.version"))
osInfo.put("serverInfo", context.getServerInfo())