我需要检查浏览器的用户代理,看它是否是IE6。不过,我不应该使用小脚本(我们有严格的没有小脚本策略)来做到这一点。

目前我使用

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

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

什么是做到这一点使用JSTL,EL等和干净的方式不小脚本?

有帮助吗?

解决方案

<c:set var="browser" value="${header['User-Agent']}" scope="session"/>

其他提示

<c:if test="${fn:contains(header['User-Agent'],'MSIE')}"></c:if>

如果您使用弹簧移动框架可以使用以下来检查设备类型

<%@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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top