现在的位置: 首页 > 综合 > 正文

jsp页面el表达式区分操作系统

2017年12月27日 ⁄ 综合 ⁄ 共 659字 ⁄ 字号 评论关闭
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/tld/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<%
String userAgent = request.getHeader("User-Agent");
String deviceOS = "";

if(userAgent.indexOf("Android")>0 || userAgent.indexOf("iPhone")>0){
	deviceOS = "phone";
}

 %>
<title>开机启动</title>

</head>

<body>
<%= userAgent%>
<%= deviceOS%>
	<center>
		<c:if test='<%=deviceOS == "phone" %>'>
			<img alt="" src="${img}"  width="80%"/>
		</c:if>
		<c:if test='<%=deviceOS == "" %>'>
			<img alt="" src="${img}" />
		</c:if>
	</center>
 
</body>
</html>

注意el表达式中的双引号 '<%= deviceOS == "phone" %>'

抱歉!评论已关闭.