Last active
October 27, 2016 00:07
-
-
Save NKjoep/7467609 to your computer and use it in GitHub Desktop.
JSP User Agent analyzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | |
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> | |
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> | |
<c:set var="ua" value="${fn:toLowerCase(header['User-Agent'])}" /> | |
<c:set var="chrome" value="${fn:contains(ua, 'chrome') && !fn:contains(ua, 'msie')}" /> | |
<fmt:formatNumber var="chrome_version" value="${ chrome ? fn:substringBefore(fn:substringAfter(ua, 'chrome/'), '.') : 0}" /> | |
<c:set var="ff" value="${fn:contains(ua, 'firefox') && !fn:contains(ua, 'opera')}" /> | |
<fmt:formatNumber var="ff_version" value="${ ff ? fn:substringBefore(fn:substringAfter(ua, 'firefox/'), '.') : 0}" /> | |
<c:set var="opera" value="${fn:contains(ua, 'opera')}" /> | |
<fmt:formatNumber var="opera_version" value="${opera ? | |
( fn:contains(ua, 'version/') ? | |
fn:substringBefore(fn:substringAfter(ua, 'version/'), '.') | |
: fn:substringBefore(fn:substringAfter(ua, 'opera '), '.') ) | |
: 0}" /> | |
<c:set var="ms" value="${fn:contains(ua, 'msie')}" /> | |
<fmt:formatNumber var="ms_version" value="${ ms ? fn:substringBefore(fn:substringAfter(ua, 'msie '), '.') : 0 }" /> | |
<c:set var="android" value="${fn:contains(ua, 'android')}" /> | |
<fmt:formatNumber var="android_version" value="${ android ? fn:substringBefore(fn:substringAfter(ua, 'android '), '.') : 0 }" /> | |
<c:set var="ios" value="${fn:contains(ua, 'ipad')||fn:contains(ua, 'iphone')||fn:contains(ua, 'ipod')}" /> | |
<fmt:formatNumber var="ios_version" value="${ ios ? fn:substringBefore(fn:substringAfter(ua, 'os '), '_') : 0 }" /> | |
ua: <c:out value="${ua}" /> | |
<br /> | |
<br /> | |
chrome: <c:out value="${chrome}" />, <c:out value="${chrome_version}" /> | |
<br /> | |
ff: <c:out value="${ff}" />, <c:out value="${ff_version}" /> | |
<br /> | |
opera: <c:out value="${opera}" />, <c:out value="${opera_version}" /> | |
<br /> | |
ms: <c:out value="${ms}" />, <c:out value="${ms_version}" /> | |
<br /> | |
android: <c:out value="${android}" />, <c:out value="${android_version}" /> | |
<br /> | |
ios: <c:out value="${ios}" />, <c:out value="${ios_version}" /> | |
<br /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment