JSTL1.1必须在Servlet2.4和JSP2.0以上的窗口才能正常工作
以下为自己在学习过种的记录
判断
条件语句
1.相当于if...else....
2.相当于逻辑于判断
3.相当于if...
在查询显示下拉列表的时候,如果循环的下拉列表数据与用户提交的数据相等,那么默认显示该数据为被选中状态
以下为自己在学习过种的记录
判断
<c:set var="name" value="VictorySoft" scope="session"/>
<c:if test="${name eq \"VictorySoft\"}">
<c:out value="正确"/>
</c:if>
条件语句
1.相当于if...else....
1.
<c:set var="flag" value="3"></c:set>
<c:choose>
<c:when test="${flag == \"1\"}">
<c:out value="${flag}"></c:out>
</c:when>
<c:when test="${flag == \"2\"}">
<c:out value="${flag}"></c:out>
</c:when>
<c:otherwise>
<c:out value="3"></c:out>
</c:otherwise>
</c:choose>
2.
<c:choose>
<c:when test="${bean.role == \"a\"}">
<c:out value="欢迎光临,${bean.name}先生"/>
</c:when>
<c:otherwise>
<c:out value="欢迎光临,${bean.name}女士"/>
</c:otherwise>
</c:choose>
2.相当于逻辑于判断
<c:choose>
<c:when test="${not empty showData}"> //如果不为空即为真
<c:forEach var="bean" items="${showData}">
<tr>
<td>${bean.name }</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td>暂无数据</td>
</tr>
</c:otherwise>
</c:choose>
3.相当于if...
<c:if test="${list!=null}">
<c:forEach var="bean" items="${list}">
<tr>
<td><c:out value="${bean.name}"/></td>
</tr>
</c:forEach>
</c:if>
<%
String str = "123-4567-890";
request.setAttribute("str",str);
%>
<c:forTokens items="${str}" delims="-" var="s">
<c:out value="${s}"/>
</c:forTokens>
在查询显示下拉列表的时候,如果循环的下拉列表数据与用户提交的数据相等,那么默认显示该数据为被选中状态
<select name="district">
<option value="">--默认--</option>
<c:choose>
<c:when test="${list!=null}">
<c:forEach var="cityBean" items="${list}">
<option value="<c:out value="${cityBean.city }"/>" <c:if test="${cityBean.city==bean.district}">selected</c:if>><c:out value="${cityBean.city }"/></option>
</c:forEach>
</c:when>
</c:choose>
</select>