Java Tutorial/JSTL/Browser Type
Версия от 17:44, 31 мая 2010; (обсуждение)
Check Browser
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.ru/jstl/core-rt" prefix="c-rt" %>
<html>
<head>
<title>Check Browser</title>
</head>
<body>
<c-rt:choose>
<c-rt:when test="<%=request.getHeader(\"User-Agent\").indexOf(\"MSIE\")!=-1%>">
You are using Internet Explorer
</c-rt:when>
<c-rt:otherwise>
You are using Netscape, or some other browser....
</c-rt:otherwise>
</c-rt:choose>
</body>
</html>
Use Choose to Check the Browser Type
<%@ page language="java" contentType="text/html" %>
<%@ taglib prefix="c_rt" uri="http://java.sun.ru/jstl/core_rt" %>
<html>
<head>
<title>Browser Check</title>
</head>
<body bgcolor="white">
<% String userAgent = request.getHeader("User-Agent"); %>
<c_rt:choose>
<c_rt:when test="<%= userAgent.indexOf("MSIE") != -1 %>" >
You"re using Internet Explorer.
</c_rt:when>
<c_rt:when test="<%= userAgent.indexOf("Mozilla") != 1 %>" >
You"re probably using Netscape.
</c_rt:when>
<c_rt:otherwise>
You"re using a browser I don"t know about.
</c_rt:otherwise>
</c_rt:choose>
</body>
</html>