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

后端 未结 3 716
野的像风
野的像风 2020-12-18 20:49

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 u

相关标签:
3条回答
  • 2020-12-18 21:17

    If you are using spring-mobile framework you can use following to check device type

    <%@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>
    
    0 讨论(0)
  • 2020-12-18 21:20
    <c:set var="browser" value="${header['User-Agent']}" scope="session"/>
    
    0 讨论(0)
  • 2020-12-18 21:30
    <c:if test="${fn:contains(header['User-Agent'],'MSIE')}"></c:if>
    
    0 讨论(0)
提交回复
热议问题