Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check the browser's user agent in a JSP page using JSTL, EL?

I need to check the browser's user-agent to see if it is IE6. However I shouldn't use scriptlets (we have a strict no scriptlets policy) to do this.

Currently I use

<%
String ua = request.getHeader( "User-Agent" );
boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
%>

<% if( isMSIE ){ %>
<div>
<% } %>

What is the cleanest way to do this using JSTL, EL, etc and not scriptlets?

like image 435
Christopher Tokar Avatar asked Jun 09 '09 08:06

Christopher Tokar


2 Answers

<c:set var="browser" value="${header['User-Agent']}" scope="session"/>
like image 139
laginimaineb Avatar answered Sep 19 '22 12:09

laginimaineb


<c:if test="${fn:contains(header['User-Agent'],'MSIE')}"></c:if>
like image 36
Zoltan Avatar answered Sep 17 '22 12:09

Zoltan