public static final byte BROWSER_IE = 1; public static final byte BROWSER_FIREFOX = 2; public static final byte BROWSER_MOZILLA = 3; public static final byte BROWSER_OPERA = 4; public static final byte BROWSER_CHROME = 5; public static final byte BROWSER_ANDROID = 6; public static final byte BROWSER_MAC = 7; public static final byte BROWSER_IOS = 8; public static final byte BROWSER_EDGE = 9; public static final byte BROWSER_UNKNOWN = 0; /** * 获得用户浏览器ua * * @param request * @return String 浏览器类型 */ public static byte getUserAgent(HttpServletRequest request) { String ua = request.getHeader("User-Agent"); ua = ua.toLowerCase(); byte result = BROWSER_UNKNOWN; if (ua.indexOf("firefox") > 0) { result = BROWSER_FIREFOX; } if (ua.indexOf("opera") > 0) { result = BROWSER_OPERA; } if (ua.indexOf("msie") > 0 || ua.indexOf("trident") > 0) { result = BROWSER_IE; } if (ua.indexOf("chrome") > 0) { result = BROWSER_CHROME; } if (ua.indexOf("android") > 0) { result = BROWSER_ANDROID; } if (ua.indexOf("mac os") > 0) { result = BROWSER_MAC; } if (ua.indexOf("ios") > 0) { result = BROWSER_IOS; } if (ua.indexOf("edge") > 0) { result = BROWSER_EDGE; } return result; }
本文作者为新逸网络,转载请注明。