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

Christopher Tokar picture Christopher Tokar · Jun 9, 2009 · Viewed 37.1k times · Source

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?

Answer

laginimaineb picture laginimaineb · Jun 9, 2009
<c:set var="browser" value="${header['User-Agent']}" scope="session"/>