前台获取信息

![这样的](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) || [];   
        //如果需要获取浏览器版本号:match[2]   
        switch(match[1]){   
        case "msie":      //ie  
            return "Internet Explorer "+parseInt(match[2]);
            break;   
        case "webkit":     //safari or chrome   
            return "safari or chrome"+parseInt(match[2]);
            break;   
        case "opera":      //opera   
            return "opera"+parseInt(match[2]);
            break;   
        case "mozilla":    //Firefox   
            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)) {
            // 多次反向代理后会有多个IP值,第一个为真实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());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值