18

我需要检查浏览器的用户代理,看看它是否是 IE6。但是我不应该使用 scriptlet(我们有严格的 no scriptlets 政策)来做到这一点。

目前我使用

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

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

使用 JSTL、EL 等而不是 scriptlet 的最简洁的方法是什么?

4

3 回答 3

25
<c:set var="browser" value="${header['User-Agent']}" scope="session"/>
于 2009-06-09T08:22:06.360 回答
21
<c:if test="${fn:contains(header['User-Agent'],'MSIE')}"></c:if>
于 2009-10-07T11:57:29.503 回答
2

如果您使用的是spring-mobile框架,您可以使用以下方法检查设备类型

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
    <c:choose> 
        <c:when test="${currentDevice.normal}"><p>"Welcome desktop user"</p> </c:when>
        <c:when test="${currentDevice.mobile}"><p>"Welcome mobile user"</p>  </c:when>
        <c:when test="${currentDevice.tab}"><p>"Welcome tab user"</p> </c:when>
    </c:choose>
于 2015-10-01T15:21:42.483 回答