我需要检查浏览器的用户代理,看看它是否是IE6。然而,我不应该使用scriptlets (我们有严格的no scriptlets策略)来做这件事。
目前我使用的是
<%
String ua = request.getHeader( "User-Agent" );
boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
%>
<% if( isMSIE ){ %>
<div>
<% } %>
使用JSTL、EL等而不是scriptlet的最干净的方式是什么?
发布于 2009-06-09 08:22:06
<c:set var="browser" value="${header['User-Agent']}" scope="session"/>
发布于 2009-10-07 11:57:30
<c:if test="${fn:contains(header['User-Agent'],'MSIE')}"></c:if>
发布于 2015-10-01 23:21:42
如果您使用的是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>
https://stackoverflow.com/questions/968800
复制相似问题