<c:choose>用于条件选择,他和<c:when><c:otherwise>一起使用,他们只能组合在一起 使用<c:when>代表了<c:choose>的一个条件分支,他必须以<c:choose>作为他的父标签
他必须在<c:otherwise>之前出现,只要遵寻这两个规则,使用起来很简单,下面给出代码:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<jsp:useBean id="user" class="UserBean"/>
<c:set value="56" target="${user}" property="age"/>
<html>
<head>
<title>JSTL:c:choose</title>
</head>
<body>
<c:choose>
<c:when test="${user.age <=18}">
<font color="blue">
</c:when>
<c:when test="${user.age<=30&&user.age>18}">
<font color="red">
</c:when>
<c:otherwise>
<font color="green">
</c:otherwise>
</c:choose>
你的年龄是:<c:out value="${user.age}"/>
</body>
</html>
<c:out>打印js语句时请注意加 escapeXml="false"防转义,大小写敏感
<c:if test="${fn:length(requestScope.msg)>0}">
<%out.println("<script>alert('"+request.getAttribute("msg")+"')</script>");%> (这两种方法等效)
<c:out value="<script>alert('${requestScope.msg}')</script>" escapeXml="false" />
</c:if>